Docker Community Forums

Share and learn in the Docker community.

connect netcore app to mongo using compose


(Benadavid) #1

I can’t seem to connect my app container to the mongodb container

here is the mongo class inside my app

public BaseDao(string dbName)
        {
            m_mongoClient = new MongoClient("mongodb://localhost:27017");
            m_mongoDb = m_mongoClient.GetDatabase(dbName);
        }

here is my docker-compose

version: '3.4'

services:
  app:
    image: vinnie_app:latest
    depends_on:
      - 'mongodb'
  mongodb:
    image: mongo:latest
    container_name: "mongodb"
    ports:
      - 27017:27017

and my docker-compose.override

version: '3.4'

services:
  app:
    build: ./app
    environment:
      - ASPNETCORE_ENVIRONMENT=Staging
      - NODE_ENV=staging
      - ASPNETCORE_URLS=http://*:50000
      - MONGODB_URI='mongodb://mongo:27017/'
    ports:
      - 50000:50000

I get a 500 error when I try to fetch stuff from the database from the app container. What’s the error and how do I connect my app container to the mongodb?? I run the containerized app at http://192.168.99.100:50000/