繁体   English   中英

如何在 docker-compose 中指定卷主机路径?

[英]How to specify volume host path in docker-compose?

我想在多个容器之间共享一个卷,并在主机上指定这个卷的路径。

我使用了以下设置:

version: '3'
services:
    service1:
        image: image1
        volumes:
            - volume1:/volume1
    service2:
        image: image2
        volumes:
            - volume1:/volume1
volumes:
  volume1:
    driver: local                 # meaning?
    driver_opts:
      o: bind                     # meaning?
      type: none                  # meaning?
      device: /volume1            # the path on the host 

但我不确定driver: localtype: noneo: bind选项。

我想要一个常规卷(比如不指定任何driverdriver_opts ),只是能够指定主机上的路径。

您正在寻找bind mount 指定volumes键意味着您正在 Docker 机器中创建一个用于持久存储的卷。 尽管名称如此,但volume不一定与volumes相关。

使用类似的东西:

version: '3'
services:
  service1:
    image: image1
    volumes:
      - type: bind # Host and Docker machines have identical views to the same directory; changes propagate both ways
        source: . # Host machine directory to mount
        target: /app # Docker machine directory to be mapped to

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM