Search in sources :

Example 1 with CreateContainerResponse

use of com.github.dockerjava.api.command.CreateContainerResponse in project dockerunit by qzagarese.

the class DefaultServiceBuilder method startContainer.

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();
}
Also used : ContainerException(com.github.qzagarese.dockerunit.exception.ContainerException) StartContainerCmd(com.github.dockerjava.api.command.StartContainerCmd) CreateContainerResponse(com.github.dockerjava.api.command.CreateContainerResponse)

Example 2 with CreateContainerResponse

use of com.github.dockerjava.api.command.CreateContainerResponse in project tutorials by eugenp.

the class ContainerLiveTest method whenRunningContainer_thenStopContainer.

@Test
public void whenRunningContainer_thenStopContainer() throws InterruptedException {
    // when
    CreateContainerResponse container = dockerClient.createContainerCmd("alpine:3.6").withCmd("sleep", "10000").exec();
    Thread.sleep(3000);
    dockerClient.startContainerCmd(container.getId()).exec();
    // then
    dockerClient.stopContainerCmd(container.getId()).exec();
}
Also used : CreateContainerResponse(com.github.dockerjava.api.command.CreateContainerResponse) Test(org.junit.Test)

Example 3 with CreateContainerResponse

use of com.github.dockerjava.api.command.CreateContainerResponse in project tutorials by eugenp.

the class ContainerLiveTest method whenCreatingContainer_thenMustReturnContainerId.

@Test
public void whenCreatingContainer_thenMustReturnContainerId() {
    // when
    CreateContainerResponse container = dockerClient.createContainerCmd("mongo:3.6").withCmd("--bind_ip_all").withName("mongo").withHostName("baeldung").withEnv("MONGO_LATEST_VERSION=3.6").withPortBindings(PortBinding.parse("9999:27017")).exec();
    // then
    assertThat(container.getId(), is(not(null)));
}
Also used : CreateContainerResponse(com.github.dockerjava.api.command.CreateContainerResponse) Test(org.junit.Test)

Example 4 with CreateContainerResponse

use of com.github.dockerjava.api.command.CreateContainerResponse in project tutorials by eugenp.

the class ContainerLiveTest method whenRunningContainer_thenKillContainer.

@Test
public void whenRunningContainer_thenKillContainer() throws InterruptedException {
    // when
    CreateContainerResponse container = dockerClient.createContainerCmd("alpine:3.6").withCmd("sleep", "10000").exec();
    dockerClient.startContainerCmd(container.getId()).exec();
    Thread.sleep(3000);
    dockerClient.stopContainerCmd(container.getId()).exec();
    // then
    dockerClient.killContainerCmd(container.getId()).exec();
}
Also used : CreateContainerResponse(com.github.dockerjava.api.command.CreateContainerResponse) Test(org.junit.Test)

Example 5 with CreateContainerResponse

use of com.github.dockerjava.api.command.CreateContainerResponse in project tutorials by eugenp.

the class ContainerLiveTest method whenHavingContainer_thenInspectContainer.

@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();
    assertThat(containerResponse.getId(), is(container.getId()));
}
Also used : InspectContainerResponse(com.github.dockerjava.api.command.InspectContainerResponse) CreateContainerResponse(com.github.dockerjava.api.command.CreateContainerResponse) Test(org.junit.Test)

Aggregations

CreateContainerResponse (com.github.dockerjava.api.command.CreateContainerResponse)12 Test (org.junit.Test)6 DockerClientException (com.github.dockerjava.api.exception.DockerClientException)2 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)2 PullImageResultCallback (com.github.dockerjava.core.command.PullImageResultCallback)2 ArrayList (java.util.ArrayList)2 CreateContainerCmd (com.github.dockerjava.api.command.CreateContainerCmd)1 InspectContainerResponse (com.github.dockerjava.api.command.InspectContainerResponse)1 StartContainerCmd (com.github.dockerjava.api.command.StartContainerCmd)1 InternalServerErrorException (com.github.dockerjava.api.exception.InternalServerErrorException)1 Bind (com.github.dockerjava.api.model.Bind)1 Container (com.github.dockerjava.api.model.Container)1 LogConfig (com.github.dockerjava.api.model.LogConfig)1 Volume (com.github.dockerjava.api.model.Volume)1 ContainerException (com.github.qzagarese.dockerunit.exception.ContainerException)1 TJob (io.elastest.etm.model.TJob)1 TJobExecution (io.elastest.etm.model.TJobExecution)1 WaitForMessagesHandler (io.elastest.etm.test.util.StompTestUtils.WaitForMessagesHandler)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1