Home > Software design >  Can't run a MongoDB image in docker
Can't run a MongoDB image in docker

Time:10-06

I am going to use MongoDB for my personal project and connect it with my local code. I created a container using command below:

docker run --name mymongo -d mongo -e MONGODB_DATABASE=namemongo -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=toor -p 27019:27017

But it didn't start. Output of command docker container ls -a:

CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS                      PORTS     NAMES
5bbcbce61c28   mongo     "docker-entrypoint.s…"   About a minute ago   Exited (2) 54 seconds ago             mymongo

docker exec -it 5bbcbce61c28 /bin/bash:

Error response from daemon: Container 5bbcbce61c284cc53b431e8d49e157b788ea6f0f70d57ca13aeefe5757c01983 is not running

I tried a docker start 5bbcbce61c28(it returns 5bbcbce61c28), but when i try command above it has similar error

CodePudding user response:

You need to put all the docker options before the image name like this

docker run --name mymongo -d -e MONGODB_DATABASE=namemongo -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=toor -p 27019:27017 mongo 
  • Related