Docker容器未运行报错排查:detached模式启动仍失败
Alright, let's break down why you're hitting that Error from daemon: container is not running message and fix it step by step.
Why the Container Isn't Running
- The root issue is your initial
docker runcommand is incomplete. When you ransh "docker run -d --name mongocontainer19", you didn't specify which image to use (like the officialmongoimage). Docker has no clue what to spin up here—either the container fails to create entirely, or it creates and immediately exits because there's no persistent process to keep it alive. - You can confirm this by running
docker ps -a; you'll seemongocontainer19listed with a status ofExited.
Why -it and Sleep Didn't Help
These flags only work if the container is actually running. Since the core problem (missing image) wasn't fixed, adding interactive mode or sleep commands won't change anything—the container still can't stay up.
Step-by-Step Fix
Clean up the broken container (if it was created):
docker rm mongocontainer19Start a valid MongoDB container (specify the official
mongoimage):docker run -d --name mongocontainer19 mongoDocker will automatically pull the
mongoimage if you don't have it locally, and the MongoDB daemon will run in the background to keep the container alive.Verify the container is running:
docker psYou should see
mongocontainer19with a status ofUp X minutes/hours.Run mongodump successfully:
Now you can execute your backup command withdocker exec:docker exec mongocontainer19 mongodump --out /dumpIf you want to save the backup to your local machine, mount a volume when starting the container:
docker run -d --name mongocontainer19 -v /your/local/backup/path:/dump mongo docker exec mongocontainer19 mongodump --out /dump
Bonus Troubleshooting Tip
If you ever run into container startup issues again, check the logs to see exactly what went wrong:
docker logs mongocontainer19
This will show you error messages from the container's startup process to help you debug faster.
内容的提问来源于stack exchange,提问作者configureMe

