hala alrefai
hala alrefai

Reputation: 11

Docker Compose with mongodb is creating a new empty db

I am trying to connect docker compose with my local mongodb , everything works fine and connection is working but my db is empty inside the container , i cant see my old data , however my local database is full . i am using windows for now for testing , this is how my docker looks like

version: "3"
    services:
      api:
        container_name : docker-node-mongo    
        build: .
        ports:
          - "3500:3001"
          - "5858:5858"
        links:
          - mongo
      mongo:
        container_name : mongo
        image: mongo
        volumes:
          - c:/data/db:/data/db
        ports:
          - '27017:27017'

i understand that the trick is with volumes: for my mongo . - data:/data/db , ./data/db:/data/db , $HOME/data/db , nothing works.

please help

Upvotes: 1

Views: 3235

Answers (2)

Steve Boyd
Steve Boyd

Reputation: 1357

Further review of the Dockerfile for mongo here shows that it is exposing two volumes. You are only mapping one of those. You might consider changing your docker-compose.yml file to include the configdb volume.

version: "3"
    services:
      api:
        container_name : docker-node-mongo    
        build: .
        ports:
          - "3500:3001"
          - "5858:5858"
        links:
          - mongo
      mongo:
        container_name : mongo
        image: mongo
        volumes:
          - c:/data/db:/data/db
          - c:/data/configdb:/data/configdb
        ports:
          - '27017:27017'

Upvotes: 2

Steve Boyd
Steve Boyd

Reputation: 1357

Assuming you are running "Docker Destop" on Windows. Your volume settings in your docker-compose file looks correct. However, on Windows you need to configure some additional settings to make a Windows drive visible to Docker containers.

  1. Select "Settings" from the Docker tray icon
  2. Select "Shared Drives"
  3. Check the appropriate boxes next to the drive letters
  4. Click "Apply"
  5. Enter you login credentials when they are requested.

Note: If you subsequently change your login or password, you will need to use the "Reset credentials" link at the bottom of the "Shared Drives" settings page.

Upvotes: 0

Related Questions