1

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

2 Answers 2

2

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'
Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

Thanks, but i already gave permission to share C:\ and that does not change anything , it setill create new database instead of loading my current .
Sorry for assuming. I've posted another answer which may be more helpful.
Thank you for your time and effort :) , now i have this error Mongodb is not connected error - MongoNetworkError: failed to connect to server [mongo:27017] on first connect [MongoNetworkError

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.