How to change default port of mongodb-atlas-local

Hi, I’m trying to setup local atlas deployment using the mongodb/mongodb-atlas-local docker image as described here: https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-docker/
But I can’t find any solution to change the port of database. I can using mapping of course such as:

services:
mongodb:
image: mongodb/mongodb-atlas-local
environment:
- MONGODB_INITDB_ROOT_USERNAME=user
- MONGODB_INITDB_ROOT_PASSWORD=pass
ports:
- 27018:27017

The issue is that the replica set has the host as “localhost:27017” and I can’t connect it using the mapped port 27018.

I am having a similar issue as Martin_Forejt.

The docker image mongodb/mongodb-atlas-local:7.0.16 starts and runs for about a minute then panic terminates. The container logs termination message:

Error: error checking mongod: error pinging: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: localhost:27017, Type: RSGhost, Average RTT: 341641 }, ] }

I changed the Docker compose file to port map 27017:27017. There is no change. My docker compose.

services:
  dba:
    image: mongodb/mongodb-atlas-local:7.0.16
    env_file:
      - .env.docker.local
    container_name: dba
    volumes:
      - dba-data:/data/db
      - dba-config:/data/configdb
    ports:
      - 27017:27017

volumes:
  dba-data:
  dba-config:

Running the atlas local image from the command line successfully starts mongo atlas local and allows connections. What’s missing from the docker compose configuration to allow this container to start successfully?

My development environment is MacOs 15.2, Docker Desktop 4.37.1.

@Martin_Forejt can I check if you’re connecting with directConnection=true ?

Hi @Jonny_Roberts No, I’m not connection with directConnection=true because I don’t want to. I want it to behave exactly the same in dev mode like in atlas production.

So I need to change the port of mongo and host of replica set to localhost, but it looks it’s not possible?

EDIT: @Chris_Norris after a bit more investigation I think you may have bumped into an issue with changing the hostname. When the hostname changes (in this case to dba) , and you stop the container you also need to remove the volume; if you compose up with the old volume and new hostname, this’ll cause the error you’re seeing.

So, can you try docker compose down -v to stop the container and remove the volume, then docker compose up and it should work again (with 7.0.16, which is fine - I’ve updated the example compose file and added the compose up and down commands)

Can you give this compose file a try, please:

services:
  dba:
    hostname: mongodb
    image: mongodb/mongodb-atlas-local:7.0.16
    
   ...

and then:

docker compose down -v
docker compose up

@Jonny_Roberts it’s possible to pass mongod.conf file somehow to mongo? I tried to replace it inside container (`/etc/mongod.conf) but the configuration is not used :frowning:
This is really bad that configuration of mongo in this atlas version is so restricted…

So it looks like the mongodb is run with this arguments:

argv: [
    'mongod',
    '--replSet',
    'docker-service-name',
    '--dbpath',
    '/data/db',
    '--keyFile',
    '/data/configdb/keyfile',
    '--maxConns',
    '32200',
    '--bind_ip_all',
    '--setParameter',
    'mongotHost=docker-service-hostname:27027',
    '--setParameter',
    'searchIndexManagementHostAndPort=docker-service-hostname:27027',
    '--transitionToAuth'
  ],

But how to configure them? @Jonny_Roberts

Adding hostname to the config fixed it. Thanks for your help @Jonny_Roberts

Here’s my working configuration
docker-compose-yml

services:
  dba:
    image: mongodb/mongodb-atlas-local:8.0.4
    hostname: mongodb
    env_file:
      - .env.docker.local # passwords and stuff
    container_name: dba
    volumes:
      - dba-data:/data/db
      - dba-config:/data/configdb
    ports:
      - 27018:27017

volumes:
  dba-data:
  dba-config:

Connection string ``mongodb://localhost:27018/?directConnection=true`

1 Like

Hi @Martin_Forejt ok, thanks for the clarification. Currently the requirement of directConnection is as designed, but I will reach out to you directly as I would like to learn more about your use case here. Thanks.

I have a similar use case where I need to call ttlMonitorEnabled=false with setParameter for our CI. The easiest way would be to pass the parameter at mongod startup. Unfortunately this option is unavailable from commandline, nor /etc/mongod.conf.

We resorted to spinning up an extra thread to call mongosh --eval 'db.adminCommand({ setParameter:1, ttlMonitorEnabled: false })' some time after the service is healthy, but this is hardly optimal.

Please consider allowing a hook to set startup parameters!