but when the container is restarted, I got this error message and I’m unable to connect again
Creating your cluster MyLocalContainer
1/2: Starting your local environment...
Error: "MyLocalContainer" deployment already exists and is currently in "running" state
Error: currently there are no deployments
Connection string: mongodb://root:root@localhost:27017/?directConnection=true
I tried removing the deployment name but every time that the container restarts it create another deployment and I should re-setup again.
I have encountered the same issue. If I try to start the container again after that first error (Error: "MyLocalContainer" deployment...) Jose posted I get the following:
Creating your cluster MyLocalContainer
2024-02-06T19:11:38.382999473Z 1/2: Starting your local environment...
2024-02-06T19:11:38.425274647Z 2/2: Creating your deployment MyLocalContainer...
2024-02-06T19:11:38.587681695Z Error: exit status 125: Error: network name mdb-local-MyLocalContainer already used: network already exists
Awesome! Thank you @Brayden_Tidwell : I was able to use that entrypoint methodology to address our issue.
Here is what I wound up using to be able to restart the container and preserve the data after restart, stop, and compose down: start-atlas.sh
#!/bin/bash
cleanup () {
# stop service and clean up here
echo "stopping atlas deployment"
atlas deployments stop MyMongo --type local 2>/dev/null
echo "stopping podman containers"
podman stop --all
exit 0
}
trap "cleanup" EXIT
# 2>/dev/null is used to silence output about listing atlas instances other than local
PODMAN_HAS_MONGO_CONTAINER=$(podman ps --all 2>/dev/null | grep 'MyMongo')
PODMAN_HAS_MONGO_NETWORK=$(podman network ls 2>/dev/null | grep 'mdb-local-MyMongo')
DEPLOYMENT_INFO=$(atlas deployments list 2>/dev/null | grep 'MyMongo')
if [[ $PODMAN_HAS_MONGO_CONTAINER ]]; then
# If missing network, create it (happens after docker compose down)
if ! [[ $PODMAN_HAS_MONGO_NETWORK ]]; then
# silence the update check
atlas config set skip_update_check true 2>/dev/null
echo "creating podman network:"
podman network create mdb-local-MyMongo
fi
# Restart a deployment
echo "starting podman containers"
podman start --all
fi
if [[ $DEPLOYMENT_INFO ]]; then
atlas deployments start MyMongo --type local 2>/dev/null
else
# silence the update check
atlas config set skip_update_check true 2>/dev/null
atlas deployments setup MyMongo --type local --username root --password root --port 27017 --bindIpAll --force 2>/dev/null
fi
sleep infinity &
wait $!
docker-compose.yml
my_mongo:
container_name: my_mongo
image: mongodb/atlas:v1.14.2
privileged: true
ports:
- "27017:27017"
entrypoint: /home/scripts/start-atlas.sh
volumes:
- ./scripts/start-atlas.sh:/home/scripts/start-atlas.sh
- /var/run/docker.sock:/var/run/docker.sock # <---- didn't really find this to be necessary included because it was in the orignal docs
- mongodb-data:/var/lib/containers # <---- needed to perserve podman containers for restart after docker compose down
I was also able to use the container in our GitHub Actions by using the following action: