


The problem is that some application does not run in the foreground. Otherwise, it thinks that your applications stops and shutdown the container. Your container immediately stops unless the commands keep running in foreground.ĭocker requires your command to keep running in the foreground. However, there is a problem with -d option. Instead of running with docker run -i -t image your-command, using -d is recommended because you can run your container with just one command and you don’t need to detach terminal of container by hitting Ctrl + P + Q. Had to do: docker run -entrypoint "/bin/sh" -it alpine/git Note that for alpine, Marinos An reports in the comments:ĭocker run -t -d alpine/git does not keep the process up. d ps -aĬONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESĤa50fd9e9189 centos "/bin/bash" 8 seconds ago Up 2 seconds wonderful_wright That was initially reported in kalyani-chaudhari's answer and detailed in jersey bean's answer. In that case, you don't need any additional command and this is enough: docker run -t -d centos More recent versions of docker authorize to run a container both in detached mode and in foreground mode ( -t, -i or -it) That means, when run in background ( -d), the shell exits immediately. Use the comment form below to give us feedback or ask questions concerning this article.The centos dockerfile has a default command bash.
#DOCKER RUN IMAGE DOESNT END BASH HOW TO#
That’s it! In this article, we have shown how to run a Docker container in the background in detached mode. How to Remove Docker Images, Containers and Volumes.How to Name or Rename Docker Containers.
#DOCKER RUN IMAGE DOESNT END BASH INSTALL#
Install Docker and Learn Basic Container Manipulation in CentOS and RHEL 7/6 – Part 1.You might also like to read these following related Docker articles. If you want to stop the above container or any other running container, use the following command (replace 301aef99c1f3 with the actual container ID). In addition, to reattach to a detached container, use docker attach command. To list all containers, run the following command (default shows just running). First, stop it from the foreground mode by pressing, then run it in a detached mode as shown: # docker run -d -rm -p 8000:80 -p 8443:443 -name pandorafms pandorafms/pandorafms:latest To run a Docker container in the background, use the use -d=true or just -d option. Which means you can not run any other commands while the container is running.

The disadvantage of running a container in the foreground is that you can not access the command prompt anymore, as you can see from the screenshot above. This example shows how to start a Docker container in foreground mode: # docker run -rm -ti -p 8000:80 -p 8443:443 -name pandorafms pandorafms/pandorafms:latest Importantly, the -rm option tells Docker to automatically remove the container when it exits. You can also attach it to one or more file descriptors ( STDIN, STDOUT and/or STDERR) using the -a= flag. There are also command line options to configure it more such as -t to allocate a pseudo-tty to the process, and -i to keep STDIN open even if not attached.
