com.github.dockerjava.api.command.InspectContainerResponse Java Examples

The following examples show how to use com.github.dockerjava.api.command.InspectContainerResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateContainerCmdIT.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("Duplicates")
@Test
public void createContainerWithShmPidsLimit() throws DockerException {
    assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_23));

    HostConfig hostConfig = new HostConfig().withPidsLimit(2L);
    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withHostConfig(hostConfig).withCmd("true").exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(is(emptyString())));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainerResponse.getHostConfig().getPidsLimit(), is(hostConfig.getPidsLimit()));
}
 
Example #2
Source File: CreateContainerCmdIT.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Test(expected = ConflictException.class)
public void createContainerWithName() throws DockerException {
    String containerName = "container_" + dockerRule.getKind();

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withName(containerName)
            .withCmd("env").exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(is(emptyString())));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainerResponse.getName(), equalTo("/" + containerName));

    dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withName(containerName)
            .withCmd("env")
            .exec();
}
 
Example #3
Source File: ContainerState.java    From testcontainers-java with MIT License 6 votes vote down vote up
/**
 * Get the actual mapped port for a given port exposed by the container.
 * Should be used in conjunction with {@link #getHost()}.
 *
 * @param originalPort the original TCP port that is exposed
 * @return the port that the exposed port is mapped to, or null if it is not exposed
 */
default Integer getMappedPort(int originalPort) {
    Preconditions.checkState(this.getContainerId() != null, "Mapped port can only be obtained after the container is started");

    Ports.Binding[] binding = new Ports.Binding[0];
    final InspectContainerResponse containerInfo = this.getContainerInfo();
    if (containerInfo != null) {
        binding = containerInfo.getNetworkSettings().getPorts().getBindings().get(new ExposedPort(originalPort));
    }

    if (binding != null && binding.length > 0 && binding[0] != null) {
        return Integer.valueOf(binding[0].getHostPortSpec());
    } else {
        throw new IllegalArgumentException("Requested port (" + originalPort + ") is not mapped");
    }
}
 
Example #4
Source File: StartContainerCmdIT.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Test
public void existingHostConfigIsPreservedByBlankStartCmd() throws DockerException {

    String dnsServer = "8.8.8.8";

    // prepare a container with custom DNS
    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
            .withHostConfig(newHostConfig()
                    .withDns(dnsServer))
            .withCmd("true").exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(is(emptyString())));

    // start container _without_any_customization_ (important!)
    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    // The DNS setting survived.
    assertThat(inspectContainerResponse.getHostConfig().getDns(), is(notNullValue()));
    assertThat(Arrays.asList(inspectContainerResponse.getHostConfig().getDns()), contains(dnsServer));
}
 
Example #5
Source File: SerializableContainerState.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
public SerializableContainerState(InspectContainerResponse.ContainerState containerState) {
    if(containerState != null) {
        this.status = containerState.getStatus();
        this.startedAt = containerState.getStartedAt();
        this.running = containerState.getRunning();
        this.paused = containerState.getPaused();
        this.restarting = containerState.getRestarting();
        this.oomKilled = containerState.getOOMKilled();
        this.dead = containerState.getDead();
        this.pid = containerState.getPid();
        this.exitCode = containerState.getExitCode();
        this.error = containerState.getError();
        this.startedAt = containerState.getStartedAt();
        this.finishedAt = containerState.getFinishedAt();
    }
}
 
Example #6
Source File: CreateContainerCmdIT.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createContainerWithNanoCPUs() throws DockerException {
    Long nanoCPUs = 1000000000L;

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
        .withCmd("sleep", "9999")
        .withHostConfig(newHostConfig()
            .withNanoCPUs(nanoCPUs))
        .exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(is(emptyString())));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainerResponse.getHostConfig().getNanoCPUs(), is(nanoCPUs));
}
 
Example #7
Source File: ResultCallback.java    From Core with MIT License 6 votes vote down vote up
private Map<String, String> getEnvironmentVariables(InspectContainerResponse info) {
    String[] unformattedArray =  info.getConfig().getEnv();

    if(unformattedArray == null || unformattedArray.length == 0) {
        return  new HashMap<>(0);
    }

    Map<String, String> formattedMap = new HashMap<>(unformattedArray.length);

    for (String environmentVariable: unformattedArray) {
        String[] parts = environmentVariable.split("=");
        if (parts.length == 2) {
            formattedMap.put(parts[0], parts[1]);
        }
    }
    return formattedMap;
}
 
Example #8
Source File: CreateContainerCmdIT.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createContainerWithMemorySwappiness() throws DockerException {
    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withCmd("sleep", "9999")
            .withHostConfig(newHostConfig()
                    .withMemorySwappiness(42L))
            .exec();
    assertThat(container.getId(), not(is(emptyString())));
    LOG.info("Created container {}", container.toString());

    dockerRule.getClient().startContainerCmd(container.getId()).exec();
    LOG.info("Started container {}", container.toString());

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient()
            .inspectContainerCmd(container.getId())
            .exec();
    LOG.info("Container Inspect: {}", inspectContainerResponse.toString());
    assertSame(42L, inspectContainerResponse.getHostConfig().getMemorySwappiness());
}
 
Example #9
Source File: DockerStatus.java    From testcontainers-java with MIT License 6 votes vote down vote up
/**
 * Based on this status, is this container running, and has it been doing so for the specified amount of time?
 *
 * @param state                  the state provided by InspectContainer
 * @param minimumRunningDuration minimum duration to consider this as "solidly" running, or null
 * @param now                    the time to consider as the current time
 * @return true if we can conclude that the container is running, false otherwise
 */
public static boolean isContainerRunning(InspectContainerResponse.ContainerState state,
                                         Duration minimumRunningDuration,
                                         Instant now) {
    if (state.getRunning()) {
        if (minimumRunningDuration == null) {
            return true;
        }
        Instant startedAt = DateTimeFormatter.ISO_INSTANT.parse(
            state.getStartedAt(), Instant::from);

        if (startedAt.isBefore(now.minus(minimumRunningDuration))) {
            return true;
        }
    }
    return false;
}
 
Example #10
Source File: MesosClusterTest.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Test
public void dockerExposeResourcesPorts() throws Exception {
    List<MesosAgent> containers = CLUSTER.getAgents();

    for (MesosAgent container : containers) {
        ArrayList<Integer> ports = ResourceUtil.parsePorts(container.getResources());
        InspectContainerResponse response = DockerClientFactory.build().inspectContainerCmd(container.getContainerId()).exec();
        Map bindings = response.getNetworkSettings().getPorts().getBindings();
        for (Integer port : ports) {
            Assert.assertTrue(bindings.containsKey(new ExposedPort(port)));
        }
    }
}
 
Example #11
Source File: CreateContainerCmdIT.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void createContainerWithTmpFs() throws DockerException {
    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
            .withHostConfig(new HostConfig().withTmpFs(Collections.singletonMap("/tmp", "rw,noexec,nosuid,size=50m"))).exec();

    assertThat(container.getId(), not(is(emptyString())));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
    assertThat(inspectContainerResponse.getHostConfig().getTmpFs().get("/tmp"), equalTo("rw,noexec,nosuid,size=50m"));
}
 
Example #12
Source File: CreateContainerCmdIT.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void createContainerWithAlias() throws DockerException {
    String containerName1 = "containerAlias_" + dockerRule.getKind();
    String networkName = "aliasNet" + dockerRule.getKind();

    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd()
            .withName(networkName)
            .withDriver("bridge")
            .exec();

    assertNotNull(createNetworkResponse.getId());

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withHostConfig(newHostConfig()
                    .withNetworkMode(networkName))
            .withCmd("sleep", "9999")
            .withName(containerName1)
            .withAliases("server" + dockerRule.getKind())
            .exec();

    assertThat(container.getId(), not(is(emptyString())));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId())
            .exec();

    ContainerNetwork aliasNet = inspectContainerResponse.getNetworkSettings().getNetworks().get(networkName);
    assertThat(aliasNet.getAliases(), hasItem("server" + dockerRule.getKind()));
}
 
Example #13
Source File: Docker.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
private void logMounts(String containerId) {
  InspectContainerResponse exec = getClient().inspectContainerCmd(containerId).exec();
  List<Mount> mounts = exec.getMounts();
  log.debug("There are {} mount(s) in the container {}:", mounts.size(), containerId);
  for (int i = 0; i < mounts.size(); i++) {
    Mount mount = mounts.get(i);
    log.debug("{}) {} -> {} ({})", i + 1, mount.getSource(), mount.getDestination(), mount.getMode());
  }
}
 
Example #14
Source File: InspectContainerCmdIT.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void inspectContainerNodeProperty() throws DockerException {
    Map<String, String> label = Collections.singletonMap("inspectContainerNodeProperty", UUID.randomUUID().toString());
    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
            .withLabels(label)
            .exec();

    Container containerResult = dockerRule.getClient().listContainersCmd()
            .withShowAll(true)
            .withLabelFilter(label)
            .exec()
            .get(0);

    String name = containerResult.getNames()[0];

    InspectContainerResponse containerInfo = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    InspectContainerResponse.Node node = containerInfo.getNode();
    if (isSwarm(dockerRule.getClient())) {
        assertThat(node, is(notNullValue()));
        assertThat(node.getAddr(), is(notNullValue()));
        assertThat(node.getId(), is(notNullValue()));
        assertThat(node.getIp(), is(notNullValue()));
        assertThat(node.getLabels(), is(notNullValue()));
        assertThat(node.getLabels().get("com.github.dockerjava.test"), is("docker-java"));
        assertThat(node.getCpus(), is(greaterThanOrEqualTo(1)));
        assertThat(node.getMemory(), is(greaterThanOrEqualTo(64 * 1024 * 1024L)));
        assertThat("/" + node.getName() + containerInfo.getName(), is(name));
    } else {
        assertThat(node, is(nullValue()));
    }
}
 
Example #15
Source File: DockerClientOperationTest.java    From redis-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void inspectContainer() throws ParseException {
    InspectContainerResponse inspectContainerResponse = dockerClientOperation.inspectContainer(IP, "a9079e77d1d800e88b525269d88a528fd19b86a0aa54010c04b5494cead8f7cf");
    Boolean running = inspectContainerResponse.getState().getRunning();
    String created = inspectContainerResponse.getCreated();
    System.err.println(created);
    System.err.println(running);
}
 
Example #16
Source File: CreateContainerCmdIT.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void createContainerWithCgroupParent() throws DockerException {
    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
            .withHostConfig(newHostConfig()
                    .withCgroupParent("/parent"))
            .exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(is(emptyString())));

    InspectContainerResponse inspectContainer = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainer.getHostConfig().getCgroupParent(), is("/parent"));
}
 
Example #17
Source File: DockerImpl.java    From vespa with Apache License 2.0 5 votes vote down vote up
private Optional<InspectContainerResponse> inspectContainerCmd(String container) {
    try {
        return Optional.of(dockerClient.inspectContainerCmd(container).exec());
    } catch (NotFoundException ignored) {
        return Optional.empty();
    } catch (RuntimeException e) {
        numberOfDockerApiFails.increment();
        throw new DockerException("Failed to get info for container '" + container + "'", e);
    }
}
 
Example #18
Source File: DefaultDockerClientIT.java    From junit5-docker with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("add latest to the image name if none is given")
public void shouldStartLatestContainer() {
    String containerId = defaultDockerClient.startContainer("faustxvi/simple-two-ports", emptyMap());
    List<Container> currentContainers = dockerClient.listContainersCmd().exec();
    assertThat(currentContainers).hasSize(existingContainers.size() + 1);
    InspectContainerResponse startedContainer = dockerClient.inspectContainerCmd(containerId).exec();
    assertThat(startedContainer.getConfig().getImage()).isEqualTo(WANTED_IMAGE);
}
 
Example #19
Source File: KafkaContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Override
@SneakyThrows
protected void containerIsStarting(InspectContainerResponse containerInfo, boolean reused) {
    super.containerIsStarting(containerInfo, reused);

    port = getMappedPort(KAFKA_PORT);

    if (reused) {
        return;
    }

    final String zookeeperConnect;
    if (externalZookeeperConnect != null) {
        zookeeperConnect = externalZookeeperConnect;
    } else {
        zookeeperConnect = startZookeeper();
    }

    String command = "#!/bin/bash \n";
    command += "export KAFKA_ZOOKEEPER_CONNECT='" + zookeeperConnect + "'\n";
    command += "export KAFKA_ADVERTISED_LISTENERS='" + Stream
        .concat(
            Stream.of(getBootstrapServers()),
            containerInfo.getNetworkSettings().getNetworks().values().stream()
                .map(it -> "BROKER://" + it.getIpAddress() + ":9092")
        )
        .collect(Collectors.joining(",")) + "'\n";

    command += ". /etc/confluent/docker/bash-config \n";
    command += "/etc/confluent/docker/configure \n";
    command += "/etc/confluent/docker/launch \n";

    copyFileToContainer(
        Transferable.of(command.getBytes(StandardCharsets.UTF_8), 700),
        STARTER_SCRIPT
    );
}
 
Example #20
Source File: DockerComputerSSHConnector.java    From docker-plugin with MIT License 5 votes vote down vote up
private static String getExternalIP(DockerAPI api, InspectContainerResponse ir, NetworkSettings networkSettings,
                             Ports.Binding[] sshBindings) {
    // If an explicit IP/hostname has been defined, always prefer this one
    String dockerHostname = api.getHostname();
    if (dockerHostname != null && !dockerHostname.trim().isEmpty()) {
        return dockerHostname;
    }
    // for (standalone) swarm, need to get the address of the actual host
    if (api.isSwarm()) {
        for (Ports.Binding b : sshBindings) {
            String ipAddress = b.getHostIp();
            if (ipAddress != null && !"0.0.0.0".equals(ipAddress)) {
                return ipAddress;
            }
        }
    }
    // see https://github.com/joyent/sdc-docker/issues/132
    final String driver = ir.getExecDriver();
    if (driver != null && driver.startsWith("sdc")) {
        // We run on Joyent's Triton
        // see https://docs.joyent.com/public-cloud/instances/docker/how/inspect-containers
        return networkSettings.getIpAddress();
    }
    final URI uri = URI.create(api.getDockerHost().getUri());
    if(uri.getScheme().equals("unix")) {
        // Communicating with unix domain socket. so we assume localhost
        return "0.0.0.0";
    }
    return uri.getHost();
}
 
Example #21
Source File: CreateContainerCmdIT.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("Duplicates")
@Test
public void createContainerWithShmSize() throws DockerException {
    HostConfig hostConfig = new HostConfig().withShmSize(96 * FileUtils.ONE_MB);
    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withHostConfig(hostConfig).withCmd("true").exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(is(emptyString())));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainerResponse.getHostConfig().getShmSize(), is(hostConfig.getShmSize()));
}
 
Example #22
Source File: MesosClusterTest.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Test
public void testMasterLinkedToAgents() throws UnirestException {
    List<MesosAgent> containers = CLUSTER.getAgents();
    for (MesosAgent container : containers) {
        InspectContainerResponse exec = DockerClientFactory.build().inspectContainerCmd(container.getContainerId()).exec();

        List<Link> links = Arrays.asList(exec.getHostConfig().getLinks());

        Assert.assertNotNull(links);
        Assert.assertEquals("link to zookeeper is expected", 1, links.size());
        Assert.assertEquals("minimesos-zookeeper", links.get(0).getAlias());
    }
}
 
Example #23
Source File: OneShotStartupCheckStrategy.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Override
public StartupStatus checkStartupState(DockerClient dockerClient, String containerId) {
    InspectContainerResponse.ContainerState state = getCurrentState(dockerClient, containerId);

    if (!DockerStatus.isContainerStopped(state)) {
        return StartupStatus.NOT_YET_KNOWN;
    }

    if (DockerStatus.isContainerStopped(state) && DockerStatus.isContainerExitCodeSuccess(state)) {
        return StartupStatus.SUCCESSFUL;
    } else {
        return StartupStatus.FAILED;
    }
}
 
Example #24
Source File: BrowserWebDriverContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
    driver = Unreliables.retryUntilSuccess(30, TimeUnit.SECONDS,
            Timeouts.getWithTimeout(10, TimeUnit.SECONDS,
                    () ->
                        () -> new RemoteWebDriver(getSeleniumAddress(), capabilities)));

    if (vncRecordingContainer != null) {
        LOGGER.debug("Starting VNC recording");
        vncRecordingContainer.start();
    }
}
 
Example #25
Source File: BrowserWebDriverContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void createContainerWithShmVolume() {
    try (
        BrowserWebDriverContainer webDriverContainer = new BrowserWebDriverContainer()
            .withCapabilities(new FirefoxOptions())
    ) {
        webDriverContainer.start();

        final List<InspectContainerResponse.Mount> shmVolumes = shmVolumes(webDriverContainer);

        assertEquals("Only one shm mount present", 1, shmVolumes.size());
        assertEquals("Shm mount source is correct", "/dev/shm", shmVolumes.get(0).getSource());
        assertEquals("Shm mount mode is correct", "rw", shmVolumes.get(0).getMode());
    }
}
 
Example #26
Source File: CouchbaseContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Override
protected void containerIsStarting(final InspectContainerResponse containerInfo) {
    logger().debug("Couchbase container is starting, performing configuration.");

    waitUntilNodeIsOnline();
    renameNode();
    initializeServices();
    configureAdminUser();
    configureExternalPorts();
    if (enabledServices.contains(CouchbaseService.INDEX)) {
        configureIndexer();
    }
}
 
Example #27
Source File: BesuNode.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
  LOG.info("Starting Besu Docker container: {}", besuContainerId);
  docker.startContainerCmd(besuContainerId).exec();

  LOG.info("Querying for the Docker dynamically allocated RPC port numbers");
  final InspectContainerResponse containerResponse =
      docker.inspectContainerCmd(besuContainerId).exec();
  final Ports ports = containerResponse.getNetworkSettings().getPorts();
  final int httpRpcPort = httpRpcPort(ports);
  final int wsRpcPort = wsRpcPort(ports);
  LOG.info("Http RPC port: {}, Web Socket RPC port: {}", httpRpcPort, wsRpcPort);

  final String httpRpcUrl = url(httpRpcPort);
  LOG.info("Besu Web3j service targeting: {} ", httpRpcUrl);

  final HttpService web3jHttpService = new HttpService(httpRpcUrl);
  this.jsonRpc =
      new JsonRpc2_0Web3j(web3jHttpService, pollingInterval, Async.defaultExecutorService());
  final RawJsonRpcRequestFactory requestFactory = new RawJsonRpcRequestFactory(web3jHttpService);
  final JsonRpc2_0Besu besuJsonRpc = new JsonRpc2_0Besu(web3jHttpService);
  final Eth eth = new Eth(jsonRpc);
  final Besu besu = new Besu(besuJsonRpc);
  final Eea eea = new Eea(requestFactory);
  this.accounts = new Accounts(eth);
  this.publicContracts = new PublicContracts(eth);
  this.privateContracts = new PrivateContracts(besu, eea);
  this.transactions = new Transactions(eth);
  this.ports = new NodePorts(httpRpcPort, wsRpcPort);
}
 
Example #28
Source File: MinimumDurationRunningStartupCheckStrategy.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Override
public StartupStatus checkStartupState(DockerClient dockerClient, String containerId) {
    // record "now" before fetching status; otherwise the time to fetch the status
    // will contribute to how long the container has been running.
    Instant now = Instant.now();
    InspectContainerResponse.ContainerState state = getCurrentState(dockerClient, containerId);

    if (DockerStatus.isContainerRunning(state, minimumRunningDuration, now)) {
        return StartupStatus.SUCCESSFUL;
    } else if (DockerStatus.isContainerStopped(state)) {
        return StartupStatus.FAILED;
    }
    return StartupStatus.NOT_YET_KNOWN;
}
 
Example #29
Source File: ContainerLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenHavingContainer_thenInspectContainer() {

    // when
    CreateContainerResponse container = dockerClient.createContainerCmd("alpine:3.6").withCmd("sleep", "10000").exec();

    // then
    InspectContainerResponse containerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();

    MatcherAssert.assertThat(containerResponse.getId(), Is.is(container.getId()));
}
 
Example #30
Source File: RabbitMQContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {

    values.forEach(command -> {
        try {
            ExecResult execResult = execInContainer(command.toArray(new String[0]));
            if (execResult.getExitCode() != 0) {
                logger().error("Could not execute command {}: {}", command, execResult.getStderr());
            }
        } catch (IOException | InterruptedException e) {
            logger().error("Could not execute command {}: {}", command, e.getMessage());
        }
    });
}