docker-compose: define mount for bind mount and managed mount

ぃ、小莉子 提交于 2019-12-05 09:49:02

问题


I'm using docker-compose for defining my service. In docker, there are two concepts for docker volume. Firstly is about bind mount: mount on host storage.

docker run -d --name web-app -v $HOST/location:/container/location -p 80:80 httpd:latest

Secondly is about managed mount: abstract storage, not depend on host.

docker run -d --name web-app -v /container/location -p 80:80 httpd:latest

I want to map those concepts to docker-compose. It means how can I define bind mount and managed mount when using docker-compose.


回答1:


You can find these Docker concepts in the volumes section of Docker Compose: https://docs.docker.com/compose/compose-file/#/volumes-volumedriver

Examples:

volumes:
  # Just specify a path and let the Engine create a volume
  - /container/location

  # Specify an absolute path mapping
  - ./myfolder/location:/container/location



回答2:


Although I am answering very late. But maybe it helps other people in future. Below is the configuration for both types. https://docs.docker.com/compose/compose-file/#volumes

    version: "3.2"
    services:
     web:
      image: httpd:latest
      volumes:
       - type: bind
         source: $HOST/location
         target: /container/location
       - type: volume
         source: mydata
         target: /container/location
     volumes:
      mydata:


来源:https://stackoverflow.com/questions/41299514/docker-compose-define-mount-for-bind-mount-and-managed-mount

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!