I know this question has been asked before and I've tried going through all the answers with no success. To start off, I am new to Docker so please forgive me if something obvious was missed.
Whether in docker-compose or cmd line, I can't get mongo-express to connect to Mongo DB.
Below I'm only asking about the cmd line as I would think I need to at least get that working.
Env: Windows 10 Pro with WSL2 / Ubuntu 20.04 and Docker Desktop version 20.10
mongo cmd line:
docker run -d --name mongo-dev -p 27017:27017 -v ~/mongodata:/data/db \
-e MONGO_INITDB_ROOT_USERNAME='admin' -e MONGO_INITDB_DATABASE='auth' \
-e MONGO_INITDB_ROOT_PASSWORD='pass' --hostname mongo-dev --network bridge mongo
I wait for it to fully start by checking logs:
{"t":{"$date":"2020-12-30T16:14:35.373+00:00"},"s":"I", "c":"NETWORK", "id":23016, "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
Then run mongo-express with the cmd line:
docker run -d --name me -p 8081:8081 -e ME_CONFIG_MONGODB_ADMINUSERNAME='admin' \
-e ME_CONFIG_MONGODB_ADMINPASSWORD='pass' -e ME_CONFIG_MONGODB_SERVER='mongo-dev' \
-e ME_CONFIG_MONGODB_PORT=27017 --hostname me --network bridge mongo-express
mongo-express logs:
Wed Dec 30 16:44:02 UTC 2020 retrying to connect to mongo-dev:27017 (5/5)
/docker-entrypoint.sh: line 14: mongo-dev: Name does not resolve
/docker-entrypoint.sh: line 14: /dev/tcp/mongo-dev/27017: Invalid argument
...
Error [MongoError]: failed to connect to server [mongo-dev:27017] on first connect
In the few seconds that mongo-express is running, I tried:
docker exec me ping mongo-dev and get "ping: bad address 'mongo-dev'"
(docker exec me ping me does work)
Can anyone help?
I believe my question is less about mongo-express and more about why "mongo-dev" can't be resolved within the mongo-express container.
Thanks!