What’s wrong with my settings?
Here’s my docker-compose.yml
that I start with sudo docker-compose up -d
which ends up like that:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7fa1ebd185d3 mongo "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:27017-27019->27017-27019/tcp mongodb
version: "3.8"
services:
mongodb:
image: mongo
container_name: mongodb
environment:
- MONGO_INITDB_ROOT_USERNAME=root1234356asdas
- MONGO_INITDB_ROOT_PASSWORD=324gdfgdfgasdas
volumes:
- /home/user/mongodb/database:/data/db
ports:
- '27017-27019:27017-27019'
restart: unless-stopped
I tried connecting to it using Robot 3T via localhost/127.0.0.1/0.0.0.0 but it always results in
"remote computer refusing to connect"
Thanks in advance
edit.
I tried those:
netsh interface portproxy add v4tov4 listenport=27017 listenaddress=127.0.0.1 connectport=27017 connectaddress=172.22.245.111
netsh interface portproxy add v4tov4 listenport=27017 listenaddress=127.0.0.1 connectport=27017 connectaddress=172.17.0.1
netsh interface portproxy add v4tov4 listenport=27017 listenaddress=127.0.0.1 connectport=27017 connectaddress=172.15.0.1
netsh interface portproxy add v4tov4 listenport=27017 listenaddress=0.0.0.0 connectport=27017 connectaddress=172.22.245.111
netsh interface portproxy add v4tov4 listenport=27017 listenaddress=0.0.0.0 connectport=27017 connectaddress=172.17.0.1
netsh interface portproxy add v4tov4 listenport=27017 listenaddress=0.0.0.0 connectport=27017 connectaddress=172.15.0.1
netsh interface portproxy add v4tov4 listenport=27018 listenaddress=127.0.0.1 connectport=27018 connectaddress=172.22.245.111
netsh interface portproxy add v4tov4 listenport=27018 listenaddress=127.0.0.1 connectport=27018 connectaddress=172.17.0.1
netsh interface portproxy add v4tov4 listenport=27018 listenaddress=127.0.0.1 connectport=27018 connectaddress=172.15.0.1
netsh interface portproxy add v4tov4 listenport=27018 listenaddress=0.0.0.0 connectport=27018 connectaddress=172.22.245.111
netsh interface portproxy add v4tov4 listenport=27018 listenaddress=0.0.0.0 connectport=27018 connectaddress=172.17.0.1
netsh interface portproxy add v4tov4 listenport=27018 listenaddress=0.0.0.0 connectport=27018 connectaddress=172.15.0.1
netsh interface portproxy add v4tov4 listenport=27019 listenaddress=127.0.0.1 connectport=27019 connectaddress=172.22.245.111
netsh interface portproxy add v4tov4 listenport=27019 listenaddress=127.0.0.1 connectport=27019 connectaddress=172.17.0.1
netsh interface portproxy add v4tov4 listenport=27019 listenaddress=127.0.0.1 connectport=27019 connectaddress=172.15.0.1
netsh interface portproxy add v4tov4 listenport=27019 listenaddress=0.0.0.0 connectport=27019 connectaddress=172.22.245.111
netsh interface portproxy add v4tov4 listenport=27019 listenaddress=0.0.0.0 connectport=27019 connectaddress=172.17.0.1
netsh interface portproxy add v4tov4 listenport=27019 listenaddress=0.0.0.0 connectport=27019 connectaddress=172.15.0.1
Edit this worked for me:
Connect to IP thats comes from hostname -I | cut -f 1 -d ' '
(executed inside WSL)
and mongo created as:
docker-compose.yml
version: "3.7"
services:
mongo:
container_name: container-mongodb
image: mongo:latest
restart: always
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: "jane"
MONGO_INITDB_ROOT_PASSWORD: "secret"
MONGO_INITDB_DATABASE: "mydb"
volumes:
- ./docker-entrypoint-initdb.d/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
mongo-init.js
print("Started Adding the Users.");
db = db.getSiblingDB("admin");
db.createUser({
user: "userx",
pwd: "1234",
roles: [{ role: "readWrite", db: "admin" }],
});
print("End Adding the User Roles.");
4
Answers
I cannot reproduce the problem, but here are the steps I took.
sudo
)docker compose up
(which uses the newer Compose V2)netstat -ab
in the Powershell session to see0.0.0.0:27017
is indeed listening on the windows hostlocalhost:27017
Using Docker for Windows with WSL2 Integration enabled
If you want to connect without a fancy GUI you could do the next steps:
docker exec -it MongoDB bash
mongodb
If you like to use mongodb and to see it in fancy GUI I recommend using dbvear
Try using Using
host.docker.internal:27017
instead oflocalhost:27017
.While I never used Robo 3T this solved the issue for me when I ran into the same problem with mongocompass.
As already mentioned you might want to use docker directly in windows and run
docker-compose up
in powershell.To connect from window host to linux WSL2, you could use localhost, or when it fails the WSL2 ip.
You can get it using from WSL2 with
hostname -I | cut -f 1 -d ' '