Hi,
I pull the alpine image to my Docker, then run the container from the alpine image.
The container status is always “Exited”. I am not sure what went wrong, will anyone of you can point out my issue? Below are the commands that I had ran.
Share and learn in the Docker community.
Hi,
I pull the alpine image to my Docker, then run the container from the alpine image.
The container status is always “Exited”. I am not sure what went wrong, will anyone of you can point out my issue? Below are the commands that I had ran.
The container does exactly what you tell it to do: it starts a detached container with the default entrypoint script and/or command, which by default starts /bin/sh
. Since no foreground process is specified, the process starts and exits right away since nothing is keeping it running, which in turn exits the container.
Please explain what you try to achieve.
Hi Metin,
Thank you for your reply! I want it to keep running so that I can start my coding in the container. You mentioned no foreground process is specified, I wonder what is the processes that I need to specify in order for it to keep running? Thank you.
Normally you run a process like a web server, database or anything that runs indefinitely. That is what Docker containers are for and when you want just a running environment, you use a system container (LXD) or a virtual machine. All that is true, but docker containers can be used as dev environments as well. Docker Desktop has a “Dev environments” beta feature. If you don’t have Docker Desktop or you don’t want to use that feature, you can run any command that runs practically forever in the foreground. A common practice is using sleep inf
docker run --name my_alpine -d --init alpine sleep inf
Note that --init
is required or otherwise when you run docker stop my_alpine
, it will wait 10 seconds and kill the container instead of stopping, since th sleep command will not handle the stop signal, but the init process will. It is not a big problem when it is a dev environment, but you will have to wait 10 seconds and time is money