I’m following the official steps outlined at MongoDB’s site to get MongoDB running with Docker.
I’ve followed the steps (almost) to the letter.
$ docker pull mongodb/mongodb-community-server:6.0-ubuntu2204
$ docker run --name mongodb-6.0 --platform=linux/amd64 -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password -d mongodb/mongodb-community-server:6.0-ubuntu2204
And, then … I’m stuck! I cannot connect with mongosh
.
$ docker exec -it mongo-6.0 mongosh -u admin -p password
Current Mongosh Log ID: 643ddf8b9d8b6b3b6b4bc7d1
Connecting to: mongodb://<credentials>@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.8.0
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
Hmm… okay. So, I don’t have the mongod
service running?
Well, using docker ls
I know I’ve got the container running…
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e4092196022 mongodb/mongodb-community-server:6.0.5-ubi8 "python3 /usr/local/…" 6 minutes ago Up 6 minutes 0.0.0.0:27017->27017/tcp mongo
And I’m pretty sure I do have mongod
running
$ docker exec mongo-6.0 ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mongodb 1 0.0 0.5 172248 43688 ? Ssl 00:00 0:00 /usr/bin/qemu-x86_64 /usr/bin/python3 python3 /usr/local/bin/docker-entrypoint.py mongo
mongodb 11 100 0.4 281104 33772 ? Rl 00:00 9:51 /usr/bin/qemu-x86_64 /usr/bin/mongod /usr/bin/mongod --bind_ip 127.0.0.1 --port 27017 -
mongodb 55 0.0 0.1 151596 9808 ? Rl+ Apr17 0:00 ps aux
So, I have no idea how to continue to troubleshoot. Help! 🙂
2
Answers
I am pretty sure this is an M1 Apple Silicon problem.
As you can see in the question, I passed the
--platform=linux/amd64
flag after getting errors.I retried all of my steps on an Intel based Mac and had no issues at all.
So, instead of using the Community Edition image, I'm using the Docker official image for MongoDB. 🤷🏼♂️