How to set docker mongo data volume

前端 未结 5 2058
醉话见心
醉话见心 2020-12-13 01:34

I want to use Dockerizing MongoDB and store data in local volume.

But .. failed ...

It has mongo:latest images

kerydeMacBook-Pro         


        
5条回答
  •  一整个雨季
    2020-12-13 02:05

    For anyone running MongoDB container on Windows: as described here, there's an issue when you mount volume from Windows host to MongoDB container using path (we call this local volume).

    You can overcome the issue using a Docker volume (volume managed by Docker):

    docker volume create mongodata
    

    Or using docker-compose as my preference:

    version: "3.4"
    
    services:
      ....
      
      db:
        image: mongo
        volumes:
          - mongodata:/data/db
        restart: unless-stopped
     
    volumes:
      mongodata:
    

    Tested on Windows 10 and it works

提交回复
热议问题