當前位置: 首頁>>代碼示例>>Java>>正文


Java Mount類代碼示例

本文整理匯總了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));
}
 
開發者ID:gocd-contrib,項目名稱:docker-swarm-elastic-agents,代碼行數:21,代碼來源:DockerMountsTest.java

示例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"));
}
 
開發者ID:gocd-contrib,項目名稱:docker-swarm-elastic-agents,代碼行數:27,代碼來源:DockerServiceTest.java

示例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;
    }
 
開發者ID:gocd-contrib,項目名稱:docker-swarm-elastic-agents,代碼行數:34,代碼來源:DockerMounts.java


注:本文中的com.spotify.docker.client.messages.mount.Mount類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。