My DockerFile is of the following logic:
1. Start the server in the background (with `&` at the end of the command)
2. Run some queries against the server, these are foreground processes
My goal is to keep the container running when all logics in the DockerFile has been executed. However, when I do docker run -d
, the container keeps exiting with error code 0
, after running the queries in the step 2 above.
From this post I learnt that
Exit code 0 indicates that the specific container does not have a foreground process attached.
Which is true in my case -- there's only the background server running. Why the server has to run in the background? Because if not, the runtime would be "blocked" by starting the server, and will not proceed to run the queries in step 2.
I wonder if there's a workaround for this, e.g. any magic flags that enables running the docker container without a foreground process, or maybe is there a recommended way to spin up a no-op foreground process at the end of the dockerFile, so that the container can attach to it and continue running?
Note that this question is different from Docker container will automatically stop after "docker run -d" --
I have tried docker run -t
, docker run -t -d
, docker run -it
, docker run -it -d
, and none of them work!