Search code examples
dockerdocker-containerdocker-run

Is there a min condition for a container to continue running?


Why does the container exit when the entry point specifies to run a command in the background? E.g. if I run docker run -d ubuntu bash -c "sleep 12000&" the container exits. If I run docker run -d ubuntu bash -c "sleep 12000" the container continues to run.
Isn't a process in the background sufficient to keep the container running?
Why does the sleep running in the background or foreground affect this?


Solution

  • According to Docker's mans, container is supposed to be running while

    the container’s primary process (PID 1) is running

    In your case primary process bash and container "runs" until this process exits.