Persisting data in local container based version of atlas

We are starting to develop apps using AtlasDB and for local development trying to use local, containerized version of atlasDB. We are running into the problem where, if we chose to persist data, it works once, but refuses to come up again until we wipe out the data. This seems to be same problem as identified and claimed to be resolved here: Persisting data with mongodb/mongodb-atlas-local

But I have tried the exact “solution” provided in that thread, and it does not work. To replicate simply create an empty directory, place this in the compose.yaml file and then start it up.

services:
  mongo:
    image: mongodb/mongodb-atlas-local
    container_name: 'mongo'
    restart: unless-stopped
    ports:
      - 27018:27017
    volumes:
      - mongodb_config:/data/configdb
      - mongodb_data:/data/db

volumes:
  mongodb_data:
  mongodb_config:

Once it is up, shut it down and start again - it will not start with “Primary does not exist”, eventually exiting with error 2

mongo  | panic: error checking mongod: error pinging: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: localhost:27017, Type: RSGhost, Average RTT: 1753789 }, ] }
mongo  | 
mongo  | goroutine 1 [running]:
mongo  | main.main()
mongo  |        /app/cmd/runner/main.go:65 +0x174
mongo  | {"t":{"$date":"2025-09-08T17:36:29.928+00:00"},"s":"I",  "c":"CONTROL",  "id":4784903, "ctx":"SignalHandler","msg":"Shutting down the LogicalSessionCache"}
mongo  | {"t":{"$date":"2025-09-08T17:36:29.929+00:00"},"s":"I",  "c":"-",        "id":7350601, "ctx":"SignalHandler","msg":"Shutting down the QueryAnalysisSampler"}
mongo  | {"t":{"$date":"2025-09-08T17:36:29.930+00:00"},"s":"I",  "c":"NETWORK",  "id":8314100, "ctx":"SignalHandler","msg":"Shutdown: Closing listener sockets"}

Hi @Michael_Lasevich , looks like you’re just missing hostname in your compose file. This is a little buried in our documentation (here) at the moment, but we’re working on improving that right now.

This (hostname) is essential for the local replicaset to function correctly, and is required to ensure communication between the different services within the same Docker Container network is possible, by being able to refer to this container by the same hostname between runs.

Here’s how I modified your compose file:

services:
  mongo:
    image: mongodb/mongodb-atlas-local
    container_name: 'mongo'
    restart: unless-stopped    
    hostname: mongodb
    ports:
      - 27018:27017
    volumes:
      - mongodb_config:/data/configdb
      - mongodb_data:/data/db

volumes:
  mongodb_data:
  mongodb_config:

To use this, you may find you need to docker compose down -v to remove old config data (note that any data will be removed at this point too) before doing docker compose up, and then go back to docker compose down when you want to stop the container and persist the data.

1 Like

Wow, that was simple enough - i can confirm that adding hostname makes it work. Typically in our compose setups we can use the service name as a hostname - so I am a little surprised, but it makes sense if I think about it… Thank you.

FWIW, The other way I got it to work is by mounting the entire /data dir, but that seemed like not a great solution… This is simpler

1 Like