I would like to experiment with Mongo Atlas inside Docker on my Mac. As it turns out, there is a good tutorial for this on the mongodb.com website.
However, at some point I got stuck. Let me explain: The first docker-compose provided in the tutorial seems to work for me:
services:
mongo:
image: mongodb/atlas
privileged: true
command: |
/bin/bash -c "atlas deployments setup --type local --port 27778 --bindIpAll --username root --password {your-password} --force && tail -f /dev/null"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 27778:27778
Now, when I do docker-compose up I get the following output
[+] Building 0.0s (0/0)
docker:desktop-linux
[+] Running 2/0
✔ Network atlas_default Created
✔ Container atlas-mongo-1 Created
Attaching to atlas-mongo-1
atlas-mongo-1 |
atlas-mongo-1 | [Default Settings]
atlas-mongo-1 | Deployment Name local5368
atlas-mongo-1 | MongoDB Version 7.0
atlas-mongo-1 | Port 27017
atlas-mongo-1 |
atlas-mongo-1 | Creating your cluster local5368 [this might take several minutes]
atlas-mongo-1 | 1/3: Starting your local environment...
atlas-mongo-1 | 2/3: Downloading the MongoDB binaries to your local environment...
atlas-mongo-1 | 3/3: Creating your deployment local242...
atlas-mongo-1 | Connection string: mongodb://root:psswd@localhost:27017/? directConnection=true
atlas-mongo-1 | Deployment created!
atlas-mongo-1 |
atlas-mongo-1 | connection skipped
This works find, I can connect with mongo
$> mongosh "mongodb://root:psswd@localhost:27017/?directConnection=true"
Next to this section, is Persist Data Across Runs with Docker Compose This is where it stopped working for me. I created the entrypoint.sh script and replaced the content from docker-compose.yaml with
services:
mongo:
image: mongodb/atlas
privileged: true
volumes:
- data-cni:/etc/cni
- data-containers:/var/lib/containers
- ./entrypoint.sh:/entrypoint.sh
ports:
- 27017:27017
environment:
- LOCALDEV_PASSWORD=psswd
volumes:
data-cni:
data-containers:
Now when I do docker-compose up I just get the following
[+] Building 0.0s (0/0)
docker:desktop-linux
[+] Running 2/0
✔ Network atlas_default Created
✔ Container atlas-mongo-1 Created
Attaching to atlas-mongo-1
Thats all, I guess it is somehow hanging. Also when I try to connect it fails
$> mongosh "mongodb://root:psswd@localhost:27017/?directConnection=true"
Current Mongosh Log ID: 661005b6a8795fafd1bbfa7b
Connecting to: mongodb://<credentials>@localhost:27017/? directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.3
MongoServerSelectionError: read ECONNRESET
Any sugestions what might go wrong here?
For those interested, here is the content of my entrypoint.js:
stop_atlas() {
echo "Stopping Atlas deployment..."
atlas deployments stop
}
start_atlas() {
echo "Starting Atlas deployment..."
atlas deployments start
}
trap 'stop_atlas' SIGTERM SIGINT
deployment_status=$(atlas deployments list | grep 'LOCAL')
if [[ -z "$deployment_status" ]]; then
echo "No local deployment found. Setting up..."
atlas deployments setup dev --bindIpAll --username root --password $LOCALDEV_PASSWORD --type local --port 27017 --force
else
if [[ $deployment_status == *"STOPPED"* ]]; then
start_atlas
fi
fi
while true
do
tail -f /dev/null & wait ${!}
done