Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the container created with - 'docker run -d alpine sleep infinity' goes into exited/stopped state?

Tags:

I have nothing to execute inside a container but want it to be running. So, I tried to create a container using the following command line - 'docker run -d alpine sleep infinity'. But, instead, it is going into a exited/stopped state immediately. What's the explanation?

like image 411
Anand Patel Avatar asked Sep 27 '16 15:09

Anand Patel


People also ask

Why container is getting exited?

You're running a shell in a container, but you haven't assigned a terminal: If you're running a container with a shell (like bash ) as the default command, then the container will exit immediately if you haven't attached an interactive terminal.

What is exited status in docker?

This can be caused by a container being stopped abruptly. If you were running a container in a bash shell and then control + C or lost connection - this would cause this issue.

How do I stop docker from stopping?

docker rm -f The final option for stopping a running container is to use the --force or -f flag in conjunction with the docker rm command. Typically, docker rm is used to remove an already stopped container, but the use of the -f flag will cause it to first issue a SIGKILL.

How do I make my docker container stay running?

Dockerfile Command to Keep the Container Running Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.


1 Answers

alpine is busybox-based, and doesn't provide the full array of options and extensions available in GNU tools; infinity as an option to sleep is an example of something that's unavailable.

Consider instead:

docker run -d alpine sh -c 'while sleep 3600; do :; done' 
like image 82
Charles Duffy Avatar answered Oct 07 '22 16:10

Charles Duffy