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?
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.
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.
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.
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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With