无法使用docker-compose挂载文件

时间:2018-10-08 23:22:25

标签: docker nginx docker-compose digital-ocean

我运行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上使用数字海洋。在开发中,我没有在同一OS(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的指示。任何想法出了什么问题吗?

1 个答案:

答案 0 :(得分:4)

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

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

您应该执行以下操作: - ${PWD}/frontend/conf/nginx:/etc/nginx/conf.d