I'm new to Docker and am attempting to run a container using the mongo image and connect to it using MongoDBCompass.
The command I'm using to start the container, which was modified from the image documentation is:
docker run --name some-mongo -d mongo -p 27017:27017
This results in the container exiting straight away. I noticed this when trying to connect from MongoDBCompass gave the error message connect ECONNREFUSED 127.0.0.1:27017.
Thanks in advance if anyone can help me modify the run command to keep the container running and allow me to connect using MongoDBCompass.
On the docker run
command, options are split in two groups.
You have -p 27017:27017
after the image name, so it's sent as a command to the container. Mongo doesn't understand that command, so it exits with an error.
Place the port mapping options before the image name and it'll work. Like this
docker run --name some-mongo -d -p 27017:27017 mongo