【问题标题】:Unable to mount a file with docker-compose无法使用 docker-compose 挂载文件
【发布时间】:2018-10-08 23:22:25
【问题描述】:

我运行docker-compose -f docker-compose.prod.yml up 并立即得到错误:

ERROR: for frontend  Cannot start service frontend: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/c/Users/James/Projects/mysite/frontend/conf/nginx/mysite.template\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/e7a2a699ae3e9ede0dd60b7cfdebb7f2d3adf71e8175157f3c9e88d3285796d2\\\" at \\\"/var/lib/docker/aufs/mnt/e7a2a699ae3e9ede0dd60b7cfdebb7f2d3adf71e8175157f3c9e88d3285796d2/etc/nginx/conf.d/default.conf\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

我的mysite.template 文件存在。我正在使用带有docker-machine 的数字海洋。在开发中,我没有在同一个操作系统(ubuntu 16)上运行这个问题。我在 windows 上使用 docker 工具箱进行开发。

这是来自docker-compose.prod.yml 的前端配置:

frontend:
image: nginx:stable-alpine
restart: always
networks:
  - web
  - default
volumes:
  - ${PWD}/frontend/conf/nginx/mysite.template:/etc/nginx/conf.d/default.conf
  - ${PWD}/frontend/public:/var/www/html
labels:
  - "traefik.enable=true"
  - "traefik.basic.frontend.rule=Host:mysite.com"
  - "traefik.basic.port=80"

我按照docs 的说明进行操作。有什么想法吗?

【问题讨论】:

  • 如果它可以帮助其他人登陆这里 - 如果您使用的是sudo docker-compose,${PWD} 会有所不同。试试sudo PWD=${PWD} docker-compose up

标签: docker nginx docker-compose digital-ocean


【解决方案1】:

您只能将主机目录挂载为卷,而不是 Docker 中的单个文件。

在您的 volumes 定义中,而不是这样: - ${PWD}/frontend/conf/nginx/mysite.template:/etc/nginx/conf.d/default.conf

你应该这样做: - ${PWD}/frontend/conf/nginx:/etc/nginx/conf.d

【讨论】:

  • 这行得通。谢谢你。 ${PWD}/frontend/public:/var/www/html 是否将public/ 的内容放入html/ 中?有点混乱。
  • 谢谢 - 我浪费了很多时间来解决这个问题。您的目录与文件点对于使其正常工作至关重要。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-24
  • 2020-07-05
  • 1970-01-01
  • 2016-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多