Docker-compose with atlas connection

I am using docker-compose to create applications and mongodb containers .

The below line of code creates a mongoDB container and I am referring the service name “mongodb-service” in application containers to connect to mongoDB .

I am doing A POC , where I need to connect to mongoDB atlas not to mongoDB container.
How I can connect to mongoDB atlas as a service , how to define HOST URL and user name password in that service .

  mongodb:
    image: mongo:latest
    ports:
      - 27017:27017
    networks:
      mynetwork:
        aliases:
          - mongodb-service
    volumes:
      - vol-mongo-db:/mongo/db
      - vol-mongo-configdb:/mongo/configdb

Hi @shirish_sahu and welcome to the community!!

As I understand the above statement correctly, the application is also using docker and is deployed using docker compose.
Can you please help with the connection string that the application is using currently to connect the application with the database?
If the URI is pointing towards mongodb-service, you can change the current URI with the Atlas URI instead.

Please let us know if you have any further questions.

Thanks
Aasawari

1 Like