I am creating a docker image using a Dockerfile. I would like to execute some scripts while starting the docker container. Currently I have a shell script to execute all the necessary processes
CMD ["sh","start.sh"]
I would like to execute a shell command with a process running in background example
CMD ["sh", "-c", "mongod --dbpath /test &"]
Besides the comments on your question that already pointed out a few things about Docker best practices you could anyway start a background process from within your
start.sh
script and keep thatstart.sh
script itself in foreground using thenohup
command and the ampersand (&
). I did not try it withmongod
but something like the following in yourstart.sh
script could work: