简体   繁体   中英

Can't run a MongoDB image in docker

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

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM