Reputation: 4795
There are a tons of question here on SO citing how this command alone
docker run --name mymongo --network bridge -p 27117:27117 -v "$PWD/db":/data/db -d mongo
should run mongo on port 27117. However this doesn't work for me. The container runs, but the mongo is run on its default port alone (see output from container itself):
# mongo
MongoDB shell version v4.0.4
connecting to: mongodb://127.0.0.1:27017
# mongo --port 27117
MongoDB shell version v4.0.4
connecting to: mongodb://127.0.0.1:27117/
2018-11-20T17:26:09.345+0000 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27117, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27117 :: caused by :: Connection refused :
What is going on?
Thanks a lot!
Upvotes: 0
Views: 4296
Reputation: 2439
Inside your container mongo runs on its default port, which is 27017
So, you should modify your command and specify the port mapping like this: -p 27117:27017
The full command would be this:
docker run --name mymongo --network bridge -p 27117:27017 -v "$PWD/db":/data/db -d mongo
Upvotes: 6
Reputation: 6365
With that command you are telling docker that the port is 27117, but you also need to start mongo with that port.
To do so, just add --port 27117
at the end of your command:
docker run --name mymongo --network bridge -p 27117:27117 -v "$PWD/db":/data/db -d mongo --port 27117
Upvotes: 2