Vitaliy photo

by Vitaliy M.

Conten Manager

07/23/2021

How to Keep Docker Containers Running

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
More

Related Articles

increase-revenue

7 Ways to Delight Your Customers and Help Increase Company Revenue

Today's customers require exceptional service. What modern business methods do you use to provide delightful customer service? If you're reading this article, you, at least, need some more of them, right? We have a few tips you might want to check. So let ...

contact form

13 Reasons to Add a Contact Form to Your Website

Modern digital technology is rapidly evolving. More and more ways to use them appear, as well as, functions, and, of course, methods to improve their business designs. And online forms in real time are one of the new recently emerged progress methods. ...

best software development model

The Best Software Development Model for Your Project

At the start of almost any project, one question arises: which software development model is the most suitable for successful implementation? There are many debates about the advantages and disadvantages of different models. Followers of different methodo ...