com.github.dockerjava.api.model.Bind类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中com.github.dockerjava.api.model.Bind类的一些代码示例,展示了Bind类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bind类的具体详情如下:
包路径:com.github.dockerjava.api.model.Bind
类名称:Bind

Bind介绍

[英]Represents a host path being bind mounted as a Volume in a Docker container. The Bind can be in read only or read write access mode.
[中]表示正在作为卷绑定装入Docker容器中的主机路径。绑定可以处于只读或读写访问模式。

代码示例

代码示例来源:origin: testcontainers/testcontainers-java

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) {
  6. final MountableFile mountableFile = MountableFile.forHostPath(hostPath);
  7. binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext));
  8. }

代码示例来源:origin: docker-java/docker-java

  1. @Override
  2. public Binds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
  3. throws IOException, JsonProcessingException {
  4. List<Bind> binds = new ArrayList<Bind>();
  5. ObjectCodec oc = jsonParser.getCodec();
  6. JsonNode node = oc.readTree(jsonParser);
  7. for (Iterator<JsonNode> it = node.elements(); it.hasNext();) {
  8. JsonNode field = it.next();
  9. binds.add(Bind.parse(field.asText()));
  10. }
  11. return new Binds(binds.toArray(new Bind[0]));
  12. }
  13. }

代码示例来源:origin: docker-java/docker-java

  1. @Override
  2. public boolean equals(Object obj) {
  3. if (obj instanceof Bind) {
  4. Bind other = (Bind) obj;
  5. return new EqualsBuilder()
  6. .append(path, other.getPath())
  7. .append(volume, other.getVolume())
  8. .append(accessMode, other.getAccessMode())
  9. .append(secMode, other.getSecMode())
  10. .append(noCopy, other.getNoCopy())
  11. .append(propagationMode, other.getPropagationMode())
  12. .isEquals();
  13. } else {
  14. return super.equals(obj);
  15. }
  16. }

代码示例来源:origin: docker-java/docker-java

  1. switch (parts.length) {
  2. case 2: {
  3. return new Bind(parts[0], new Volume(parts[1]));
  4. return new Bind(parts[0], new Volume(parts[1]), accessMode, seMode, nocopy, propagationMode);

代码示例来源:origin: arquillian/arquillian-cube

  1. private static final Bind[] toBinds(Collection<String> bindsList) {
  2. Bind[] binds = new Bind[bindsList.size()];
  3. int i = 0;
  4. for (String bind : bindsList) {
  5. binds[i] = Bind.parse(bind);
  6. i++;
  7. }
  8. return binds;
  9. }

代码示例来源:origin: com.github.docker-java/docker-java

  1. @Override
  2. public boolean equals(Object obj) {
  3. if (obj instanceof Bind) {
  4. Bind other = (Bind) obj;
  5. return new EqualsBuilder()
  6. .append(path, other.getPath())
  7. .append(volume, other.getVolume())
  8. .append(accessMode, other.getAccessMode())
  9. .append(secMode, other.getSecMode())
  10. .append(noCopy, other.getNoCopy())
  11. .append(propagationMode, other.getPropagationMode())
  12. .isEquals();
  13. } else {
  14. return super.equals(obj);
  15. }
  16. }

代码示例来源:origin: testcontainers/testcontainers-java

  1. private boolean checkMountableFile() {
  2. DockerClient dockerClient = client();
  3. MountableFile mountableFile = MountableFile.forClasspathResource(ResourceReaper.class.getName().replace(".", "/") + ".class");
  4. Volume volume = new Volume("/dummy");
  5. try {
  6. return runInsideDocker(
  7. createContainerCmd -> createContainerCmd.withBinds(new Bind(mountableFile.getResolvedPath(), volume, AccessMode.ro)),
  8. (__, containerId) -> {
  9. try (InputStream stream = dockerClient.copyArchiveFromContainerCmd(containerId, volume.getPath()).exec()) {
  10. stream.read();
  11. return true;
  12. } catch (Exception e) {
  13. return false;
  14. }
  15. }
  16. );
  17. } catch (Exception e) {
  18. log.debug("Failure while checking for mountable file support", e);
  19. return false;
  20. }
  21. }

代码示例来源:origin: org.arquillian.cube/arquillian-cube-docker

  1. private static final Bind[] toBinds(Collection<String> bindsList) {
  2. Bind[] binds = new Bind[bindsList.size()];
  3. int i = 0;
  4. for (String bind : bindsList) {
  5. binds[i] = Bind.parse(bind);
  6. i++;
  7. }
  8. return binds;
  9. }

代码示例来源:origin: FlowCI/flow-platform

  1. .withBinds(new Bind(repoPath.toString(), volume),
  2. new Bind(Paths.get(repoPath.getParent().toString(), REPOSITORY).toString(), mvnVolume))
  3. .withWorkingDir(File.separator + fileName)
  4. .withCmd(BASH, "-c", cmd)

代码示例来源:origin: jenkinsci/docker-build-step-plugin

  1. private static Bind parseOneBind(String definition) throws IllegalArgumentException {
  2. try {
  3. // first try as-is (using ":" as delimiter) in order to
  4. // preserve whitespace in paths
  5. return Bind.parse(definition);
  6. } catch (IllegalArgumentException e1) {
  7. try {
  8. // give it a second try assuming blanks as delimiter
  9. return Bind.parse(definition.replace(' ', ':'));
  10. } catch (Exception e2) {
  11. throw new IllegalArgumentException(
  12. "Bind mount needs to be in format 'hostPath containerPath[ rw|ro]'");
  13. }
  14. }
  15. }

代码示例来源:origin: org.testcontainers/testcontainers

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) {
  6. final MountableFile mountableFile = MountableFile.forHostPath(hostPath);
  7. binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext));
  8. }

代码示例来源:origin: com.github.docker-java/docker-java

  1. @Override
  2. public Binds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
  3. throws IOException, JsonProcessingException {
  4. List<Bind> binds = new ArrayList<Bind>();
  5. ObjectCodec oc = jsonParser.getCodec();
  6. JsonNode node = oc.readTree(jsonParser);
  7. for (Iterator<JsonNode> it = node.elements(); it.hasNext();) {
  8. JsonNode field = it.next();
  9. binds.add(Bind.parse(field.asText()));
  10. }
  11. return new Binds(binds.toArray(new Bind[0]));
  12. }
  13. }

代码示例来源:origin: stackoverflow.com

  1. void testServiceCallWithNoKeyPropertyFound() {
  2. Component componentUnderTest = new Component() {
  3. Integer getProperties(String key) {
  4. return null; // property should not be found
  5. }
  6. Request getRequest() {
  7. return new Request(...); //this request should not contain a property named "key",
  8. }
  9. Bind getBind() {
  10. return new Bind(...); //this bind should not contain a property named "key"
  11. }
  12. String makeServiceCall(String url) {
  13. if (url.endsWith("null")) {
  14. return success;
  15. }
  16. throw new AssertionError("expected url ending with null, but was " + url);
  17. }
  18. };
  19. componentUnderTest.activate();
  20. assertThat(componentUnderTest.getSomeString(), equalTo("success"));
  21. }

代码示例来源:origin: jenkinsci/docker-plugin

  1. public FormValidation doCheckVolumesString(@QueryParameter String volumesString) {
  2. try {
  3. final String[] strings = splitAndFilterEmpty(volumesString, "\n");
  4. for (String s : strings) {
  5. if (s.equals("/")) {
  6. return FormValidation.error("Invalid volume: path can't be '/'");
  7. }
  8. final String[] group = s.split(":");
  9. if (group.length > 3) {
  10. return FormValidation.error("Wrong syntax: " + s);
  11. } else if (group.length == 2 || group.length == 3) {
  12. if (group[1].equals("/")) {
  13. return FormValidation.error("Invalid bind mount: destination can't be '/'");
  14. }
  15. Bind.parse(s);
  16. } else if (group.length == 1) {
  17. new Volume(s);
  18. } else {
  19. return FormValidation.error("Wrong line: " + s);
  20. }
  21. }
  22. } catch (Throwable t) {
  23. return FormValidation.error(t.getMessage());
  24. }
  25. return FormValidation.ok();
  26. }

代码示例来源:origin: com.github.docker-java/docker-java

  1. switch (parts.length) {
  2. case 2: {
  3. return new Bind(parts[0], new Volume(parts[1]));
  4. return new Bind(parts[0], new Volume(parts[1]), accessMode, seMode, nocopy, propagationMode);

代码示例来源:origin: ContainerSolutions/minimesos

  1. private CreateContainerCmd getBaseCommand() {
  2. String hostDir = MesosCluster.getClusterHostDir().getAbsolutePath();
  3. List<Bind> binds = new ArrayList<>();
  4. binds.add(Bind.parse("/var/run/docker.sock:/var/run/docker.sock:rw"));
  5. binds.add(Bind.parse("/sys/fs/cgroup:/sys/fs/cgroup"));
  6. binds.add(Bind.parse(hostDir + ":" + hostDir));
  7. if (getCluster().getMapAgentSandboxVolume()) {
  8. binds.add(Bind.parse(String.format("%s:%s:rw", hostDir + "/.minimesos/sandbox-" + getClusterId() + "/" + hostName, MESOS_AGENT_WORK_DIR + hostName + "/slaves")));
  9. }
  10. CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag())
  11. .withName(getName())
  12. .withHostName(hostName)
  13. .withPrivileged(true)
  14. .withVolumes(new Volume(MESOS_AGENT_WORK_DIR + hostName))
  15. .withEnv(newEnvironment()
  16. .withValues(getMesosAgentEnvVars())
  17. .withValues(getSharedEnvVars())
  18. .createEnvironment())
  19. .withPidMode("host")
  20. .withLinks(new Link(getZooKeeper().getContainerId(), "minimesos-zookeeper"))
  21. .withBinds(binds.stream().toArray(Bind[]::new));
  22. MesosDns mesosDns = getCluster().getMesosDns();
  23. if (mesosDns != null) {
  24. cmd.withDns(mesosDns.getIpAddress());
  25. }
  26. return cmd;
  27. }

代码示例来源:origin: com.github.qzagarese/dockerunit-core

  1. @Override
  2. public CreateContainerCmd build(ServiceDescriptor sd, CreateContainerCmd cmd, Volume v) {
  3. Bind[] binds = cmd.getBinds();
  4. String hostPath = v.useClasspath()
  5. ? Thread.currentThread().getContextClassLoader()
  6. .getResource(v.host()).getPath()
  7. : v.host();
  8. Bind bind = new Bind(hostPath,
  9. new com.github.dockerjava.api.model.Volume(v.container()),
  10. AccessMode.fromBoolean(v.accessMode().equals(Volume.AccessMode.RW)));
  11. List<Bind> bindsList = new ArrayList<>();
  12. if(binds != null) {
  13. bindsList.addAll(Arrays.asList(binds));
  14. }
  15. bindsList.add(bind);
  16. return cmd.withBinds(bindsList);
  17. }

代码示例来源:origin: ContainerSolutions/minimesos

  1. @Override
  2. protected CreateContainerCmd dockerCommand() {
  3. return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
  4. .withNetworkMode("host")
  5. .withBinds(Bind.parse("/var/run/docker.sock:/tmp/docker.sock"))
  6. .withCmd("-internal", String.format("consul://%s:%d", consul.getIpAddress(), ConsulConfig.CONSUL_HTTP_PORT))
  7. .withName(getName());
  8. }

代码示例来源:origin: Kurento/kurento-java

  1. .withBinds(new Bind(hostConfigFilePath, configVol));
  2. new Bind(testFilesPath, testFilesVolume, AccessMode.ro),
  3. new Bind(workspacePath, workspaceVolume, AccessMode.rw),
  4. new Bind(configFilePath, configVol));
  5. } else {
  6. new Bind(testFilesPath, testFilesVolume, AccessMode.ro),
  7. new Bind(workspacePath, workspaceVolume, AccessMode.rw));

代码示例来源:origin: jenkinsci/docker-plugin

  1. binds.add(Bind.parse(vol));
  2. } else if (vol.equals("/")) {
  3. throw new IllegalArgumentException("Invalid volume: path can't be '/'");

相关文章