.toArray(ExposedPort[]::new); createCommand.withExposedPorts(portArray);
@Override protected CreateContainerCmd dockerCommand() { ArrayList<ExposedPort> exposedPorts = new ArrayList<>(); exposedPorts.add(new ExposedPort(getServicePort())); ArrayList<Integer> resourcePorts = ResourceUtil.parsePorts(getResources()); for (Integer port : resourcePorts) { exposedPorts.add(new ExposedPort(port)); } return getBaseCommand() .withExposedPorts(exposedPorts.toArray(new ExposedPort[exposedPorts.size()])); }
public String createContainerWithPorts(String image, int[] ports, String... command){ ExposedPort[] exposedPorts=new ExposedPort[ports.length]; for(int i=0;i < ports.length;i++){ exposedPorts[i]=ExposedPort.tcp(ports[i]); } CreateContainerResponse container = dockerClient.createContainerCmd(image) .withCmd(command) .withExposedPorts(exposedPorts) .exec(); return container.getId(); }
@Override public CreateContainerCmd build(ServiceDescriptor sd, CreateContainerCmd cmd, PortBinding pb) { List<ExposedPort> ports = new ArrayList<>(Arrays.asList(cmd.getExposedPorts())); ExposedPort containerPort = pb.protocol() .equals(Protocol.TCP) ? ExposedPort.tcp(pb.exposedPort()) : ExposedPort.udp(pb.exposedPort()); ports.add(containerPort); Ports bindings = cmd.getPortBindings(); if (bindings == null) { bindings = new Ports(); } bindings.bind(containerPort, pb.hostIp() .isEmpty() ? Binding.bindPort(pb.hostPort()) : Binding.bindIpAndPort(pb.hostIp(), pb.hostPort())); return cmd.withExposedPorts(ports) .withPortBindings(bindings); }
@Override protected CreateContainerCmd dockerCommand() { return DockerClientFactory.build() .createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withEnv(newEnvironment() .withValues(getMesosDNSEnvVars()) .createEnvironment()) .withCmd("-v=2", "-config=/etc/mesos-dns/config.json") .withExposedPorts(new ExposedPort(Integer.valueOf(DNS_PORT), InternetProtocol.UDP), new ExposedPort(Integer.valueOf(DNS_PORT), InternetProtocol.TCP)) .withName(getName()); }
@Override public void beforeContainerCreated(DockerAPI api, String workdir, CreateContainerCmd cmd) throws IOException, InterruptedException { // TODO define a strategy for SSHD process configuration so we support more than openssh's sshd if (cmd.getCmd() == null || cmd.getCmd().length == 0) { if (sshKeyStrategy.getInjectedKey() != null) { cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port), // override sshd_config to force retrieval of InstanceIdentity public for as authentication "-o", "AuthorizedKeysCommand=/root/authorized_key", "-o", "AuthorizedKeysCommandUser=root" ); } else { cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port)); } } cmd.withPortSpecs(port+"/tcp"); final PortBinding sshPortBinding = PortBinding.parse(":" + port); final Ports portBindings = cmd.getPortBindings(); if(portBindings != null) { portBindings.add(sshPortBinding); cmd.withPortBindings(portBindings); } else { cmd.withPortBindings(sshPortBinding); } cmd.withExposedPorts(ExposedPort.parse(port+"/tcp")); }
.withStdinOpen((Boolean) getProperty("interactive", true)) .withName(DockerUtil.normalizeResourceName(config.getDeploymentName() + "_" + getId())) .withExposedPorts(exposedPorts.toArray(new ExposedPort[exposedPorts.size()])) .withPortBindings(portBindings); if (volumes != null && !volumes.isEmpty()) {
.createContainerCmd(imageNameWithVer) .withName(imageName().replace('/', '_') + '_' + this.hashCode()) .withExposedPorts(exposedPorts) .withCmd(args); if (env != null && !env.isEmpty()) {
@Test public void testWithAContainerWithLabels() throws InterruptedException { Map<String, String> labels = new LinkedHashMap<>(); labels.put("service.type", "http-endpoint"); labels.put("ssl", "true"); CreateContainerResponse container = client.createContainerCmd("nginx") .withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443)) .withPortBindings(PortBinding.parse("80")) .withLabels(labels) .exec(); AtomicBoolean done = new AtomicBoolean(); Future<Void> future = Future.future(); future.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); done.set(false); client.startContainerCmd(container.getId()).exec(); Future<Void> future2 = Future.future(); future2.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future2); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(1); DockerService service = bridge.getServices().get(0); assertThat(service.records()).hasSize(1); assertThat(service.records().get(0).getLocation().getString("endpoint")).startsWith("https"); }
@Test public void testWithAContainerWithLabels() throws InterruptedException { Map<String, String> labels = new LinkedHashMap<>(); labels.put("service.type", "http-endpoint"); labels.put("ssl", "true"); CreateContainerResponse container = client.createContainerCmd("nginx") .withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443)) .withPortBindings(PortBinding.parse("80")) .withLabels(labels) .exec(); AtomicBoolean done = new AtomicBoolean(); Future<Void> future = Future.future(); future.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); done.set(false); client.startContainerCmd(container.getId()).exec(); Future<Void> future2 = Future.future(); future2.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future2); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(1); DockerService service = bridge.getServices().get(0); assertThat(service.records()).hasSize(1); assertThat(service.records().get(0).getLocation().getString("endpoint")).startsWith("https"); }
@Test public void testWithAContainerWithAPort() throws InterruptedException { CreateContainerResponse container = client.createContainerCmd("nginx") .withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443)) .withPortBindings(PortBinding.parse("80")) .exec(); AtomicBoolean done = new AtomicBoolean(); Future<Void> future = Future.future(); future.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); done.set(false); client.startContainerCmd(container.getId()).exec(); Future<Void> future2 = Future.future(); future2.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future2); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(1); DockerService service = bridge.getServices().get(0); assertThat(service.records()).hasSize(1); }
@Test public void testWithAContainerWithAPort() throws InterruptedException { CreateContainerResponse container = client.createContainerCmd("nginx") .withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443)) .withPortBindings(PortBinding.parse("80")) .exec(); AtomicBoolean done = new AtomicBoolean(); Future<Void> future = Future.future(); future.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); done.set(false); client.startContainerCmd(container.getId()).exec(); Future<Void> future2 = Future.future(); future2.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future2); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(1); DockerService service = bridge.getServices().get(0); assertThat(service.records()).hasSize(1); }
@Test public void testWithAContainerWithTwoPorts() throws InterruptedException { CreateContainerResponse container = client.createContainerCmd("nginx") .withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443)) .withPortBindings(PortBinding.parse("80"), PortBinding.parse("443")) .exec(); AtomicBoolean done = new AtomicBoolean(); Future<Void> future = Future.future(); future.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); done.set(false); client.startContainerCmd(container.getId()).exec(); Future<Void> future2 = Future.future(); future2.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future2); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(1); DockerService service = bridge.getServices().get(0); assertThat(service.records()).hasSize(2); client.stopContainerCmd(container.getId()).exec(); done.set(false); Future<Void> future3 = Future.future(); future3.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future3); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); }
@Test public void testWithAContainerWithTwoPorts() throws InterruptedException { CreateContainerResponse container = client.createContainerCmd("nginx") .withExposedPorts(ExposedPort.tcp(80), ExposedPort.tcp(443)) .withPortBindings(PortBinding.parse("80"), PortBinding.parse("443")) .exec(); AtomicBoolean done = new AtomicBoolean(); Future<Void> future = Future.future(); future.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); done.set(false); client.startContainerCmd(container.getId()).exec(); Future<Void> future2 = Future.future(); future2.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future2); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(1); DockerService service = bridge.getServices().get(0); assertThat(service.records()).hasSize(2); client.stopContainerCmd(container.getId()).exec(); done.set(false); Future<Void> future3 = Future.future(); future3.setHandler(ar -> done.set(ar.succeeded())); bridge.scan(future3); await().untilAtomic(done, is(true)); assertThat(bridge.getServices()).hasSize(0); }
.withExposedPorts(port) .withEnv(env) .exec();
@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)); } return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withExposedPorts(new ExposedPort(ZooKeeperConfig.DEFAULT_ZOOKEEPER_PORT), new ExposedPort(2888), new ExposedPort(3888)) .withPortBindings(portBindings); }
cfgCmd.withExposedPorts(ports);
@Override protected CreateContainerCmd dockerCommand() { ExposedPort exposedPort = ExposedPort.tcp(MARATHON_PORT); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(MARATHON_PORT)); } return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withExtraHosts("minimesos-zookeeper:" + this.zooKeeper.getIpAddress()) .withCmd(CollectionsUtils.splitCmd(config.getCmd())) .withExposedPorts(exposedPort) .withPortBindings(portBindings); }
@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)); } ExposedPort consulHTTPPort = ExposedPort.tcp(ConsulConfig.CONSUL_HTTP_PORT); ExposedPort consulDNSPort = ExposedPort.udp(ConsulConfig.CONSUL_DNS_PORT); return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withCmd("agent", "-server", "-bootstrap", "-client", "0.0.0.0") .withExposedPorts(consulHTTPPort, consulDNSPort) .withPortBindings(portBindings); }
@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; }