com.github.dockerjava.api.model.Bind.parse()方法的使用及代码示例

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

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

Bind.parse介绍

[英]Parses a bind mount specification to a Bind.
[中]将绑定装载规范解析为绑定。

代码示例

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

@Override
  public Binds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    List<Bind> binds = new ArrayList<Bind>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<JsonNode> it = node.elements(); it.hasNext();) {
      JsonNode field = it.next();
      binds.add(Bind.parse(field.asText()));
    }
    return new Binds(binds.toArray(new Bind[0]));
  }
}

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

private static final Bind[] toBinds(Collection<String> bindsList) {
  Bind[] binds = new Bind[bindsList.size()];
  int i = 0;
  for (String bind : bindsList) {
    binds[i] = Bind.parse(bind);
    i++;
  }
  return binds;
}

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

private static final Bind[] toBinds(Collection<String> bindsList) {
  Bind[] binds = new Bind[bindsList.size()];
  int i = 0;
  for (String bind : bindsList) {
    binds[i] = Bind.parse(bind);
    i++;
  }
  return binds;
}

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

private static Bind parseOneBind(String definition) throws IllegalArgumentException {
  try {
    // first try as-is (using ":" as delimiter) in order to 
    // preserve whitespace in paths
    return Bind.parse(definition);
  } catch (IllegalArgumentException e1) {
    try {
      // give it a second try assuming blanks as delimiter
      return Bind.parse(definition.replace(' ', ':'));
    } catch (Exception e2) {
      throw new IllegalArgumentException(
          "Bind mount needs to be in format 'hostPath containerPath[ rw|ro]'");
    }
  }
}

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

@Override
  public Binds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    List<Bind> binds = new ArrayList<Bind>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<JsonNode> it = node.elements(); it.hasNext();) {
      JsonNode field = it.next();
      binds.add(Bind.parse(field.asText()));
    }
    return new Binds(binds.toArray(new Bind[0]));
  }
}

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

public FormValidation doCheckVolumesString(@QueryParameter String volumesString) {
  try {
    final String[] strings = splitAndFilterEmpty(volumesString, "\n");
    for (String s : strings) {
      if (s.equals("/")) {
        return FormValidation.error("Invalid volume: path can't be '/'");
      }
      final String[] group = s.split(":");
      if (group.length > 3) {
        return FormValidation.error("Wrong syntax: " + s);
      } else if (group.length == 2 || group.length == 3) {
        if (group[1].equals("/")) {
          return FormValidation.error("Invalid bind mount: destination can't be '/'");
        }
        Bind.parse(s);
      } else if (group.length == 1) {
        new Volume(s);
      } else {
        return FormValidation.error("Wrong line: " + s);
      }
    }
  } catch (Throwable t) {
    return FormValidation.error(t.getMessage());
  }
  return FormValidation.ok();
}

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

private CreateContainerCmd getBaseCommand() {
  String hostDir = MesosCluster.getClusterHostDir().getAbsolutePath();
  List<Bind> binds = new ArrayList<>();
  binds.add(Bind.parse("/var/run/docker.sock:/var/run/docker.sock:rw"));
  binds.add(Bind.parse("/sys/fs/cgroup:/sys/fs/cgroup"));
  binds.add(Bind.parse(hostDir + ":" + hostDir));
  if (getCluster().getMapAgentSandboxVolume()) {
    binds.add(Bind.parse(String.format("%s:%s:rw", hostDir + "/.minimesos/sandbox-" + getClusterId() + "/" + hostName, MESOS_AGENT_WORK_DIR + hostName + "/slaves")));
  }
  CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag())
    .withName(getName())
    .withHostName(hostName)
    .withPrivileged(true)
    .withVolumes(new Volume(MESOS_AGENT_WORK_DIR + hostName))
    .withEnv(newEnvironment()
      .withValues(getMesosAgentEnvVars())
      .withValues(getSharedEnvVars())
      .createEnvironment())
    .withPidMode("host")
    .withLinks(new Link(getZooKeeper().getContainerId(), "minimesos-zookeeper"))
    .withBinds(binds.stream().toArray(Bind[]::new));
  MesosDns mesosDns = getCluster().getMesosDns();
  if (mesosDns != null) {
    cmd.withDns(mesosDns.getIpAddress());
  }
  return cmd;
}

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

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

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

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

相关文章