I'm completely a newbie to docker. I tried to start a exited container like follows,
- I listed down all available containers using
docker ps -a
. It listed the following, I entered the following commands to start the container which is in the exited stage and enter into the terminal of that image.
docker start 79b3fa70b51d
docker exec -it 79b3fa70b51d \bin\sh
It is throwing the following error.
FATA[0000] Error response from daemon: Container 79b3fa70b51d is not running
But when I start the container using docker start 79b3fa70b51d
. It throws the container ID as output which is normal if it have everything work normally. I'm not sure what causes this error. Any idea about the causes and suggestions about this would be greatly helpful for me. Thanks in advance.
Container
79b3fa70b51d
seems to only do anecho
.That means it starts, echo and then exits immediately.
The next
docker exec
command wouldn't find it running in order to attach itself to that container and execute any command: it is too late. The container has already exited.If it's not possible to start the main process again (for long enough), there is also the possibility to
commit
the container to a new image and run a new container from this image. While this is not the usual best practice workflow, I find it really useful to debug a failing script once in a while.The reason is just what the accepted answer said. I add some extra information, which may provide a further understanding about this issue.
Created
,Running
,Stopped
,Exited
,Dead
and others as I know.docker create
, docker daemon will create a container with its status ofCreated
.docker start
, docker daemon will start a existing container which its status may beCreated
orStopped
.docker run
, docker daemon will finish it in two steps:docker create
anddocker start
.docker stop
, obviously docker daemon will stop a container. Thus container would be inStopped
status.Exited
.When does the process exit? In another word, what’s the process, how did we start it?
The answer is
CMD
in a dockerfile orcommand
in the following expression, which isbash
by default in some images, i.e. ubutu:18.04.By default, docker container will exit immediately if you do not have any task running on the container.
To keep the container running in the background, try to run it with
--detach
(or-d
) argument.For examples:
In my case , i changed certain file names and directory names of the parent directory of the Dockerfile . Due to which container not finding the required parameters to start it again.
After renaming it back to the original names, container started like butter.
First of all, we have to start the docker container
After that, check the docker container:
Then execute by using the command below: