hongshengbiao
hongshengbiao

Reputation: 11

use docker-client api to start container in Java project

I am now using docker client api https://github.com/docker-java/docker-java in my Java project:

CreateContainerResponse container = 
    dockerClient
        .createContainerCmd("ubuntu:java7")
        .withCmd("true")
        .exec();
dockerClient
    .startContainerCmd(container.getId())
    .exec();

When I start a new container using docker client api,the container is created,but i also finished.I use command "sudo docker ps" to list the running container now, what I created is not shown.I want to create the running container in my Java project using the docker client api,how should I do? Thanks.

Upvotes: 1

Views: 2279

Answers (1)

Abdullah Shah
Abdullah Shah

Reputation: 780

I am not sure whats your usecase here. I think you are starting container in attached mode. As soon as you are done, the container exits. And you want that container to persist.

Use

.withTty(true)

while creating the container to detach.

Upvotes: 2

Related Questions