本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerCmd.withDns方法的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerCmd.withDns方法的具体用法?Java CreateContainerCmd.withDns怎么用?Java CreateContainerCmd.withDns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.dockerjava.api.command.CreateContainerCmd
的用法示例。
在下文中一共展示了CreateContainerCmd.withDns方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dockerCommand
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
int port = getServicePort();
ExposedPort exposedPort = ExposedPort.tcp(port);
Ports portBindings = new Ports();
if (getCluster().isMapPortsToHost()) {
portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
}
CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag())
.withName(getName())
.withExposedPorts(new ExposedPort(getServicePort()))
.withEnv(newEnvironment()
.withValues(getMesosMasterEnvVars())
.withValues(getSharedEnvVars())
.createEnvironment())
.withPortBindings(portBindings);
MesosDns mesosDns = getCluster().getMesosDns();
if (mesosDns != null) {
cmd.withDns(mesosDns.getIpAddress());
}
return cmd;
}
示例2: getBaseCommand
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
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;
}
示例3: call
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
public String call() throws Exception {
DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null);
CreateContainerCmd cfgCmd = client.createContainerCmd(imageRes);
if (commandRes != null) {
cfgCmd.withCmd(commandRes);
}
cfgCmd.withHostName(hostNameRes);
cfgCmd.withName(containerNameRes);
HostConfig hc = new HostConfig();
cfgCmd.withLinks(LinkUtils.parseLinks(linksRes).getLinks());
if (envVarsRes != null) {
cfgCmd.withEnv(envVarsRes);
}
if (exposedPortsRes != null && !exposedPortsRes.isEmpty()) {
final ExposedPort[] ports;
String[] exposedPortsSplitted = exposedPortsRes.split(",");
ports = new ExposedPort[exposedPortsSplitted.length];
for (int i = 0; i < ports.length; i++) {
ports[i] = ExposedPort.parse(exposedPortsSplitted[i]);
}
cfgCmd.withExposedPorts(ports);
}
if (cpuSharesRes != null) {
cfgCmd.withCpuShares(cpuSharesRes);
}
if (memoryLimitRes != null) {
cfgCmd.withMemory(memoryLimitRes);
}
if (dnsRes != null) {
cfgCmd.withDns(dnsRes);
}
if (extraHostsRes != null) {
cfgCmd.withExtraHosts(extraHostsRes);
}
if (portBindingsRes != null) {
cfgCmd.withPortBindings(PortBindingParser.parse(portBindingsRes));
}
if (bindMountsRes != null) {
cfgCmd.withBinds(BindParser.parse(bindMountsRes));
}
if (alwaysRestart) {
cfgCmd.withRestartPolicy(RestartPolicy.alwaysRestart());
}
CreateContainerResponse resp = cfgCmd.withPublishAllPorts(publishAllPorts).withPrivileged(privileged).exec();
InspectContainerResponse inspectResp = client.inspectContainerCmd(resp.getId()).exec();
ObjectMapper mapper = new ObjectMapper();
String serialized = mapper.writeValueAsString(inspectResp);
return serialized;
}