1

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.

4
  • Your container is probably not running. docker ps -a will show you all containers, including the stopped ones. Commented Jan 5, 2017 at 9:36
  • You say you have some code. Edit your question and include it. Commented Jan 5, 2017 at 9:38
  • Hello,thanks you reply.When I use java docker api to create and start the container,I can see what I created just now using "sudo docker ps -a". Commented Jan 6, 2017 at 2:52
  • CreateContainerResponse container = dockerClient.createContainerCmd("ubuntu:java7") .withCmd("true") .exec(); dockerClient.startContainerCmd(container.getId()).exec(); Commented Jan 6, 2017 at 2:55

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.