private <T> T runInsideDocker(DockerClient client, Consumer<CreateContainerCmd> createContainerCmdConsumer, BiFunction<DockerClient, String, T> block) { checkAndPullImage(client, TINY_IMAGE); CreateContainerCmd createContainerCmd = client.createContainerCmd(TINY_IMAGE) .withLabels(DEFAULT_LABELS); createContainerCmdConsumer.accept(createContainerCmd); String id = createContainerCmd.exec().getId(); try { client.startContainerCmd(id).exec(); return block.apply(client, id); } finally { try { client.removeContainerCmd(id).withRemoveVolumes(true).withForce(true).exec(); } catch (NotFoundException | InternalServerErrorException ignored) { log.debug("", ignored); } } }
@Override protected Void execute(StartContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/start") .resolveTemplate("id", command.getContainerId()); LOGGER.trace("POST: {}", webResource); webResource.request() .accept(MediaType.APPLICATION_JSON) .post(null) .close(); return null; }
private String startContainer(CreateContainerCmd cmd, DockerClient client) { CreateContainerResponse createResp = cmd.exec(); StartContainerCmd startCmd = client.startContainerCmd(createResp.getId()); try { startCmd.exec(); } catch (Throwable t) { throw new ContainerException(createResp.getId(), t); } return startCmd.getContainerId(); }
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; }
.withPortBindings(hostConfig.getPortBindings()) .withPublishAllPorts(hostConfig.isPublishAllPorts()) .withPrivileged(hostConfig.isPrivileged()) .exec();
dockerClient.startContainerCmd(containerId).exec();
@Override protected Void execute(StartContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/start").resolveTemplate("id", command.getContainerId()); LOGGER.trace("POST: {}", webResource); webResource.request() .accept(MediaType.APPLICATION_JSON) .post(command); return null; }
.exec(); docker.startContainerCmd(container.getId()).exec();
@Override protected Void execute(StartContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/start") .resolveTemplate("id", command.getContainerId()); LOGGER.trace("POST: {}", webResource); webResource.request() .accept(MediaType.APPLICATION_JSON) .post(null) .close(); return null; }
public void startContainer(String id, CubeContainer containerConfiguration) { this.readWriteLock.readLock().lock(); try { StartContainerCmd startContainerCmd = this.dockerClient.startContainerCmd(id); startContainerCmd.exec(); } finally { this.readWriteLock.readLock().unlock(); } }
@Override protected Void execute(StartContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/start").resolveTemplate("id", command.getContainerId()); LOGGER.trace("POST: {}", webResource); webResource.request() .accept(MediaType.APPLICATION_JSON) .post(command); return null; }
public void startContainer(String id, CubeContainer containerConfiguration) { this.readWriteLock.readLock().lock(); try { StartContainerCmd startContainerCmd = this.dockerClient.startContainerCmd(id); startContainerCmd.exec(); } finally { this.readWriteLock.readLock().unlock(); } }
public void startContainer(String id){ dockerClient.startContainerCmd(id).exec(); }
private void startContainer(String idOfContainerToStart) { try { docker.startContainerCmd(idOfContainerToStart).exec(); } catch (Exception e) { logger.error("Unable to start container " + idOfContainerToStart, e); throw new OrchestrationException(e); } }
public void startContainer(String containerName) { if (!isRunningContainer(containerName)) { log.debug("Starting container {}", containerName); getClient().startContainerCmd(containerName).exec(); log.debug("Started container {}", containerName); } else { log.debug("Container {} is already started", containerName); } }
public void startContainer(String containerName) { if (!isRunningContainer(containerName)) { log.debug("Starting container {}", containerName); getClient().startContainerCmd(containerName).exec(); log.debug("Started container {}", containerName); } else { log.debug("Container {} is already started", containerName); } }
/** * starts a {@link Container} * * @param microservice {@link Microservice} */ public void startContainer(Microservice microservice) throws NotFoundException, NotModifiedException { // long totalMemory = ((OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); // long jvmMemory = Runtime.getRuntime().maxMemory(); // long requiredMemory = (long) Math.min(totalMemory * 0.25, 256 * Constants.MiB); // // if (totalMemory - jvmMemory < requiredMemory) // throw new Exception("Not enough memory to start the container"); dockerClient.startContainerCmd(microservice.getContainerId()).exec(); }
private void connectToPortForwardingNetwork(String networkMode) { PortForwardingContainer.INSTANCE.getNetwork().map(ContainerNetwork::getNetworkID).ifPresent(networkId -> { if (!Arrays.asList(networkId, "none", "host").contains(networkMode)) { dockerClient.connectToNetworkCmd().withContainerId(containerId).withNetworkId(networkId).exec(); } }); }
public String call() throws Exception { DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null); client.startContainerCmd(id).exec(); InspectContainerResponse inspectResp = client.inspectContainerCmd(id).exec(); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(inspectResp); return serialized; }
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); } }); } }