You did not explain why you want your container to run after the exit of your script, or you expect your script to complete.
The docker container exits as soon as the CMD container completes. If you want your container to continue to work, you will need a process that will work. One option is to simply put a while loop at the end of your script:
while :; do sleep 300 done
Your script will never exit, so your container will work. If your container has a network service (web server, database server, etc.), then this is usually a process that runs for the life of the container.
If instead your script comes out unexpectedly, you probably need to look at the logs of your container ( docker logs <container> ) and possibly add some debugging to the script.
If you just ask: “How do I run a container in the background?”, Then the answer from Emil (passing the -d flag to docker run ) will help you.
larsks
source share