How to Keep Docker Containers Running

by Vitaliy M.

Content Manager

07/23/2021

Docker Containers Running

Docker containers, when run in detached mode (the most common -d option), are designed to shut down immediately after the initial entrypoint command (program that should be run when container is built from image) is no longer running in the foreground. This can cause problems because often servers or services running in Docker containers are run in the background, causing your container to shut down before you want it to.

If you would like to keep your container running in detached mode, you need to run something in the foreground. An easy way to do this is to tail the /dev/null device as the CMD or ENTRYPOINT command of your Docker image.

CMD tail -f /dev/null

This command could also run as the last step in a custom script used with CMD or ENTRYPOINT.

Sample Dockerfile

FROM ubuntu:16.04

# other commands

CMD tail -f /dev/null

Top Custom Software Development Companies

Web Development Companies

Related Articles

messaging app

People send thousands of messages to relatives, friends, partners, and employees via special apps every day. For the same reason, numerous people want to create their own service and, to succeed, they explore the issue of how to make a messaging app.T ...

Business App

Mobile solutions are available not only to large corporations, as they used to be, but also to small businesses. To gain a competitive advantage and improve service are the main reasons why brands turn ...

Music Streaming App

So many people enjoy listening to music at home, on the road, or on vacation. Not so long ago, we made up our own playlists with downloaded songs. ...

Improve Your Online Presence!

We exceed your expectations! Create a company profile and get noticed by thousands in no time!

Submit Profile