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.
FROM ubuntu:16.04 # other commands CMD tail -f /dev/null