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.

1 Like

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: ******

still not resolve this issue. Any suggestion ?

Sorry, I hope you will be able to solve this. I can’t test it on Windows server. Deleting a docker container should not delete the mounted data. On Linux processes can delete data before stopping when they get the stop signal. I don’t know if Windows has a similar feature, but you can try to test it with other images.