Run a background script inside a docker container

dockerprocess

In my Dockerfile, I run a script:

RUN /bin/sh -c scripts/init.sh

Inside init.sh, all commands ending with & are not executed: I cannot run background processes.
Any idea why?

Best Answer

I had the similar issue and something like the following helped me.

RUN nohup bash -c "scripts/init.sh &" && sleep 4

In many cases the server you started isn’t yet fully ready. To allow the server a bit more time to get ready add a sleep command. How large the argument sleep needs to depend on the service you start and you probably need to tweak it.

Read more on this Doc

Related Question