Docker Community Forums

Share and learn in the Docker community.

Not able to persist mongo docker volume if stack goes down

Hi ,
I am using docker mongo image in windows 2k16 server but unable to persist data if stack goes down.

Below is the .yml file -

version: "3.7"
services:
  mongo:
    image: library/mongo:latest
    hostname: mongo
    ports:
      - 27017:27017
    deploy:
      replicas: 1
      
  applicationservice:
    image: application_Service_Imge_Name_from_Hosted_On_Docker
    environment:
      - GRAPHIQL_PATH=/graphql
    hostname: applicationservice
    volumes:
      - C:/ProgramData/ApplicationData/Volumes:C:/data
    depends_on:
      - mongo
    deploy:
      replicas: 1

networks:
  default:
    driver: overlay
    name: ******

I can see data is created on C:/ProgramData/ApplicationData/Volumes on my local system, but when stack goes down mongo image do not load data from my local folder.

Your mongo container doesn’t have a volume. Your entire mongo database will be lost every time you delete the container. If you store tha path of the files in the database, the new database won’t know about any file.

Sorry @rimelek by mistake, I have added wrong yml file, updated correct one -

version: "3.7"
services:
  mongo:
    image: library/mongo:latest
    hostname: mongo
	volumes:
      - C:/ProgramData/ApplicationData/Volumes/Mongo/data:C:/data/db
      - C:/ProgramData/ApplicationData/Volumes/Mongo/config:C:/data/configdb
    ports:
      - 27017:27017
    deploy:
      replicas: 1
      
  applicationservice:
    image: application_Service_Imge_Name_from_Hosted_On_Docker
    environment:
      - GRAPHIQL_PATH=/graphql
    hostname: applicationservice
    volumes:
      - C:/ProgramData/ApplicationData/Volumes:C:/data
    depends_on:
      - mongo
    deploy:
      replicas: 1

networks:
  default:
    driver: overlay
    name: ******