How To Keep a Docker Container Running and Not Exiting

In this Docker blog post, I will show you how to keep a Docker container running and not exiting.

Docker containers are great for developers because they can run an application in a specific environment without installing the software locally.

One issue can arise when using Docker containers: they exit after being idle for too long! In this article, I’ll show you how to prevent your docker container from exiting with some simple methods.

How To Keep a Docker Container Running and Not Exiting

To keep a Docker container from exiting, you can use the “-d” flag when running the container to detach it and run it in the background.

Additionally, make sure that the container is running a process that doesn’t exit on its own.

If the container is exiting immediately, check the logs using “docker logs <container_name>” to see if there are any errors causing the premature exit.

To keep your containers running and exiting, I have two options for you to use that will not let the container go ideal and exit. Use either of the two (We would like to use the second option).

 docker run --name deploy2 -d ubuntu sleep infinity
 docker run --name deploy1 -d ubuntu tail -f /dev/null