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:
- name: Docker Compose
uses: isbang/compose-action@v1.5.1
with:
services: |
my_mongo
up-flags: "--build --detach --pull always --quiet-pull --wait --wait-timeout 300"
down-flags: "--volumes --remove-orphans --timeout 5"