This will sStop a container from exiting immediately on completing a command. This is useful for if you need to keep it running long enough to start a terminal session in or check some other attributes.

Tail

This command will watch continuously for output and not exit.

$ tail -f

Or

$ tail -f /dev/null

So use that as command in Dockerfile:

  • Dockerfile
      CMD ["tail", "-f", "/dev/null"]
    

Or when executing the container:

$ docker exec my-app 'tail -f /dev/null'

Interactive

Or start with interactive shell.

$ docker exec -it my-app bash