本文整理汇总了Java中com.spotify.docker.client.messages.mount.Mount类的典型用法代码示例。如果您正苦于以下问题:Java Mount类的具体用法?Java Mount怎么用?Java Mount使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mount类属于com.spotify.docker.client.messages.mount包,在下文中一共展示了Mount类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldBuildMountFromDockerMount
import com.spotify.docker.client.messages.mount.Mount; //导入依赖的package包/类
@Test
public void shouldBuildMountFromDockerMount() throws Exception {
final DockerMounts dockerMounts = DockerMounts.fromString("source=namedVolume, target=/path/in/container\ntype=bind, src=/path/in/host, target=/path/in/container2, readonly");
final Volume volume = mock(Volume.class);
when(volume.name()).thenReturn("namedVolume");
final List<Mount> mounts = dockerMounts.toMount(asList(volume));
assertThat(mounts, hasSize(2));
assertThat(mounts.get(0).type(), is("volume"));
assertThat(mounts.get(0).source(), is("namedVolume"));
assertThat(mounts.get(0).target(), is("/path/in/container"));
assertThat(mounts.get(0).readOnly(), is(false));
assertThat(mounts.get(1).type(), is("bind"));
assertThat(mounts.get(1).source(), is("/path/in/host"));
assertThat(mounts.get(1).target(), is("/path/in/container2"));
assertThat(mounts.get(1).readOnly(), is(true));
}
示例2: shouldStartContainerWithMountedVolume
import com.spotify.docker.client.messages.mount.Mount; //导入依赖的package包/类
@Test
public void shouldStartContainerWithMountedVolume() throws Exception {
requireDockerApiVersionAtLeast("1.26", "Docker volume mount.");
final String volumeName = UUID.randomUUID().toString();
final Volume volume = docker.createVolume(Volume.builder()
.name(volumeName)
.driver("local")
.labels(Collections.singletonMap("cd.go.contrib.elasticagents.dockerswarm.elasticagent.DockerPlugin", ""))
.build()
);
Map<String, String> properties = new HashMap<>();
properties.put("Image", "alpine:latest");
properties.put("Mounts", "source=" + volumeName + ", target=/path/in/container");
DockerService service = DockerService.create(new CreateAgentRequest("key", properties, "prod", new JobIdentifier(100L)), createSettings(), docker);
services.add(service.name());
final Service inspectServiceInfo = docker.inspectService(service.name());
final Mount mount = inspectServiceInfo.spec().taskTemplate().containerSpec().mounts().get(0);
assertThat(mount.source(), is(volumeName));
assertThat(mount.type(), is("volume"));
}
示例3: toMount
import com.spotify.docker.client.messages.mount.Mount; //导入依赖的package包/类
public List<Mount> toMount(List<Volume> volumes) {
if (Util.isEmpty(volumes)) {
LOG.debug("No volumes to mount.");
return Collections.emptyList();
}
final Map<String, Volume> volumeMap = volumes.stream().collect(Collectors.toMap(o -> o.name(), o -> o));
final List<Mount> mounts = new ArrayList<>();
for (DockerMount dockerMount : this) {
if (dockerMount.type().equals("volume")) {
final Volume volume = volumeMap.get(dockerMount.source);
if (volume == null) {
throw new RuntimeException(format("Volume with name `{0}` does not exist.", dockerMount.source()));
}
LOG.debug(format("Using volume `{0}`.", dockerMount.source()));
}
final Mount mount = Mount.builder()
.type(dockerMount.type())
.source(dockerMount.source())
.target(dockerMount.target())
.readOnly(dockerMount.readOnly())
.build();
mounts.add(mount);
}
return mounts;
}