docker 撰写 : absolute path for shared volumes in version 3

标签 docker docker-compose volumes

为了替换版本 2 中的 volumes_from: 指令(针对 helpyio ),我尝试了这个,但出了点问题。

version: "3"

services:
  frontend:
    ...
    volumes:
      - myVolume:/var/www:ro
  backend:
    ...
    volumes:
      - myVolume:/var/www

volumes:
  myVolume:
    driver:      local
    driver_opts:
      type:      none
      device:    "/my/local/absolute/path/"
      o:         bind

我有这样的错误

ERROR: for frontend: Cannot create container for service frontend: failed to mount local volume: mount /my/local/absolute/path/:/var/www, flags: 0x1000: no such file or directory

我还在 volumes: 选项中尝试了一些变体,但没有成功。最后一件事,我不想手动创建这个本地目录。

我肯定会遗漏一些东西,但看不到什么...有人对此用例有解决方案吗?

非常感谢

最佳答案

没有理由让您的 docker-compose.yml 变得那么复杂。你可以简单地这样做:

version: "3"

services:
  frontend:
    ...
    volumes:
      - /my/local/absolute/path/:/var/www:ro
  backend:
    ...
    volumes:
      - /my/local/absolute/path/:/var/www

关于 docker 撰写 : absolute path for shared volumes in version 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59054466/

相关文章:

macos - 在 osx 上的 bazel test env 中运行 docker

docker - GitHub 操作和 Docker-compose

linux - 在 docker 容器上持久化/etc/passwd

kubernetes - 如何将数据装载到Kubernetes上的持久存储中并在多个Pod之间共享存储?

go - 如何在实时应用程序 RethinkDB 上访问/安装/设置 Web 面板

Docker Compose : deploying different services from docker-compose. yml 到不同的主机集

git - 使用dockerfile使用https克隆位桶存储库。如何传递密码?

Docker-compose 无法运行 jar 文件,但可以使用 Dockerfile

docker - Docker:Dockerfile无法执行COPY

mongodb - docker-compose 与 MongoDb 和卷 - 似乎没有安装