[docker] Docker - Container is not running

I'm completely a newbie to docker. I tried to start a exited container like follows,

  1. I listed down all available containers using docker ps -a. It listed the following:

    docker list all images

  2. 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
    
  3. 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.

This question is related to docker docker-container

The answer is


This happens with images for which the script does not launch a service awaiting requests, therefore the container exits at the end of the script.

This is typically the case with most base OS images (centos, debian, etc.), or also with the node images.

Your best bet is to run the image in interactive mode. Example below with the node image:

docker run -it node /bin/bash

Output is

root@cacc7897a20c:/# echo $SHELL
/bin/bash

First of all, we have to start the docker container

ankit@ankit-HP-Notebook:~$  sudo docker start 3a19b39ea021

                        3a19b39ea021

After that, check the docker container:

ankit@ankit-HP-Notebook:~$  sudo docker ps -a

 CONTAINER ID        IMAGE                         COMMAND             CREATED             STATUS                   PORTS               NAMES

  3a19b39ea021        coreapps/ubuntu16.04:latest   "bash"              13 hours ago        
  Up 9 seconds                                 ubuntu1

  455b66057060        hello-world                   "/hello"            4 weeks ago         

Exited (0) 4 weeks ago                       vigorous_bardeen

Then execute by using the command below:

ankit@ankit-HP-Notebook:~$  sudo docker exec -it 3a19b39ea021 bash

root@3a19b39ea021:/# 

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.


docker run -it --entrypoint /bin/bash <imageid>

This was posted by L0j1k in the below post and worked for me.

How do I get into a Docker container's shell?


Here's a solution when the docker container exits normally and you can edit the Dockerfile.

Generally, when a docker container is run, an application is served by running a command. From the Dockerfile reference,

Both CMD and ENTRYPOINT instructions define what command gets executed when running a container. ... Dockerfile should specify at least one of CMD or ENTRYPOINT commands.

When you build a image and not specify any command with CMD or ENTRYPOINT, the base image's CMD or ENTRYPOINT command would be executed.

For example, the Official Ubuntu Dockerfile has CMD ["/bin/bash"] (https://hub.docker.com/_/ubuntu). Now, the bin/bash/ command can accept input and docker run -it IMAGE_ID command attaches STDIN to the container. The result is that you get an interactive terminal and the container keeps running.

When a command with CMD or ENTRYPOINT is specified in the Dockerfile, this command gets executed when running the container. Now, if this command can finish without requiring any input, it will finish and the container will exit. docker run -it IMAGE_ID will NOT provide the interactive terminal in this case. An example would be the docker image built from the Dockerfile below-

FROM ubuntu
ENTRYPOINT echo hello 

If you need to go to the terminal of this image, you will need to keep the container running by modifying the entrypoint command.

FROM ubuntu
ENTRYPOINT echo hello && sleep infinity 

After running the container normally with docker run IMAGE_ID, you can just go to another terminal and use docker exec -it CONTAINER_ID bash to get the container's terminal.


I have a different take on this. I could do a docker ps and see that there is a docker container running, I even tried to restart it, but as soon as I tried to get a session for it with New-PSSession -ContainerId $containerId -RunAsAdministrator It would error out, saying:

##[error]New-PSSession : The input ContainerId xxx does not exist, ##[error]or the corresponding container is not running.

My problem was I was running with network service and it did not have enough permissions to see the container, even though I had given it permissions to run docker commands (with docker security group configuration)

I didn't know how to enable working with containers, so I had to revert to running it as an admin user instead


Here is what worked for me.

Get the container ID and restart.

docker ps -a --no-trunc 

ace7ca65e6e3fdb678d9cdfb33a7a165c510e65c3bc28fecb960ac993c37ef33


docker restart ace7ca65e6e3fdb678d9cdfb33a7a165c510e65c3bc28fecb960ac993c37ef33

For anyone attempting something similar using a Dockerfile...

Running in detached mode won't help. The container will always exit (stop running) if the command is non-blocking, this is the case with bash.

In this case, a workaround would be: 1. Commit the resulting image: (container_name = the name of the container you want to base the image off of, image_name = the name of the image to be created docker commit container_name image_name 2. Use docker run to create a new container using the new image, specifying the command you want to run. Here, I will run "bash": docker run -it image_name bash

This would get you the interactive login you're looking for.


The reason is just what the accepted answer said. I add some extra information, which may provide a further understanding about this issue.

  1. The status of a container includes Created, Running, Stopped, Exited, Dead and others as I know.
  2. When we execute docker create, docker daemon will create a container with its status of Created.
  3. When docker start, docker daemon will start a existing container which its status may be Created or Stopped.
  4. When we execute docker run, docker daemon will finish it in two steps: docker create and docker start.
  5. When docker stop, obviously docker daemon will stop a container. Thus container would be in Stopped status.
  6. Coming the most important one, a container actually imagine itself holding a long time process in it. When the process exits, the container holding process would exit too. Thus the status of this container would be 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 or command in the following expression, which is bash by default in some images, i.e. ubutu:18.04.

docker run ubuntu:18.04 [command]

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:

docker pull debian

docker run -t -d --name my_debian debian
e7672d54b0c2

docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
e7672d54b0c2        debian              "bash"              3 minutes ago       Up 3 minutes                            my_debian

#now you can execute command on the container
docker exec -it my_debian bash
root@e7672d54b0c2:/# 

docker run -it <image_id> /bin/bash

Run in interactive mode executing then bash shell


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.

docker exec -it 6198ef53d943 bash
Error response from daemon: Container 6198ef53d9431a3f38e8b38d7869940f7fb803afac4a2d599812b8e42419c574 is not running

docker commit 6198ef53d943
sha256:ace7ca65e6e3fdb678d9cdfb33a7a165c510e65c3bc28fecb960ac993c37ef33

docker run -it ace7ca65e6e bash
root@72d38a8c787d:/#