Docker container stops running automatically
Docker container stops running automatically
I am trying to run the docker maven image as a container. After executing the docker run command, the container stops running automatically after a few seconds. How to keep the container running in the background?
Below is the console output
[email protected]:~# docker run -itd --name mvn maven 83e51a6f2006303715e533c84a5adedc955ef320d333505d3707b5e05316bdf2 [email protected]:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 83e51a6f2006 maven "/usr/local/bin/mvn-…" 5 seconds ago Up 2 seconds mvn [email protected]:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [email protected]:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 83e51a6f2006 maven "/usr/local/bin/mvn-…" 35 seconds ago Exited (1) 26 seconds ago mvn [email protected]:~#
vito Selected answer as best September 21, 2021
The container is exiting because the main process inside it has finished. To keep the container running, you can attach a different entrypoint to the container. Execute the below command,
docker run --entrypoint /bin/sh -itd --name mvn maven
This will keep the container running in the background.
vito Selected answer as best September 21, 2021