1

Use RestAPI to create a container with command "/bin/bash". The container is created successfully because the RestAPI returns container ID. But I can't start this container. Command "docker ps" always show no container, even after I manually start this container.

[root@CentOS Base]# curl -X POST -H "Content-Type: application/json" 127.0.0.1:4243/containers/create -d '{"Id" : "99", "Command" : "/bin/bash", "Image" : "centos", "Status" : "exit 0"}' {"Id":"c0384a81ba1e6bbb23c4268c580899f9e38afb9dec11e2107baafcf7744bf999","Warnings":null}

[root@CentOS Base]# docker start c0384a81ba1e6bbb23c4268c580899f9e38afb9dec11e2107baafcf7744bf999 c0384a81ba1e6bbb23c4268c580899f9e38afb9dec11e2107baafcf7744bf999

[root@CentOS Base]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[root@CentOS Base]#

1 Answer 1

1

docker ps -a probably does show the container. It is stopped. It's important to note that containers are designed to stop once the command executed within them has exited. So when starting the container /bin/bash is executed and after that the container stops. You need to run the container with a command that stays active. Try running with "Command" : "ping -c 1000 localhost"

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

3 Comments

I think command /bin/bash can last forever. When I use command "docker run -i -t centos /bin/bash", the new container can automatically in start state. Is there corresponding option "-i -t" in RestAPI /containers/create?
I think your api creates an image. It does not start a container.
"docker run -i -t centos /bin/bash" creates a new container. I just tried it again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.