private static PortBinding createFromSubstrings(String binding, String exposedPort) throws IllegalArgumentException { return new PortBinding(Binding.parse(binding), ExposedPort.parse(exposedPort)); }
private static PortBinding createFromSubstrings(String binding, String exposedPort) throws IllegalArgumentException { return new PortBinding(Binding.parse(binding), ExposedPort.parse(exposedPort)); }
private void startContainer(Map<String, String> env, Map<Integer, Integer> ports, Map<String, String> cmd, Consumer<String> log) { final CreateContainerResponse container = client.createContainerCmd(image) .withCmd(cmd.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(toList())) .withLabels(map(label, "true")) .withEnv(env.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(toList())) .withPortBindings(ports.entrySet().stream().map(e -> new PortBinding(Ports.Binding.bindPort(e.getKey()), ExposedPort.tcp(e.getValue()))).collect(toList())) .exec(); client.startContainerCmd(container.getId()).exec(); client.logContainerCmd(container.getId()).withFollowStream(true).withStdOut(true).withStdErr(true).exec( new LogContainerResultCallback() { public void onNext(Frame frame) { final String msg = new String(frame.getPayload()); log.accept(msg.endsWith("\n") ? msg.substring(0, msg.length() - 1) : msg); } }); } }
public String run(String image, int... ports) { String containerId = docker.createContainerCmd(image).exec().getId(); List<PortBinding> portBindings = new ArrayList<>(); if (ports != null) { for (int port : ports) { portBindings.add(new PortBinding(new Ports.Binding(port), new ExposedPort(port))); } } docker.startContainerCmd(containerId).withPortBindings(portBindings.toArray(new PortBinding[portBindings.size()])).exec(); startedContainers.add(containerId); registerShutdown(containerId); return containerId; }
portBindings.add(new PortBinding(Ports.Binding.bindPortSpec(""+hostPort), new ExposedPort(containerPort, InternetProtocol.TCP)));