Reputation: 323
I have a fundamental question about container life cycle.
For example I run the following command
Create new ubuntu container and run the bash command
docker run -it ubuntu bash
In the container's bash
exit
The new container will be in state EXITED
docker ps -a
Then I use docker start to restart the container
docker start xxxx(container name)
docker exec -it xxxx(container name) /bin/bash
In the restarted container's bash
exit
The restarted container is still running
docker ps -a
May I know the reason behind for this behavior? Thank you!
Upvotes: 0
Views: 78
Reputation: 9580
With the docker run
command:
docker run -it ubuntu bash
the container is started with the execution of the bash
command, so when you exit
from the bash
, the container also exits as bash
is the main process running inside the container.
However with the docker exec
command:
docker exec -it xxxx(container name) /bin/bash
the container is already running the command defined by the CMD
/ENTRYPOINT
and bash
is the command executed as a separate process. So, exit
ing from bash
after docker start
exits the bash
process and the main process is still continued.
Upvotes: 1