无法使用docker-compose挂载文件 [英] Unable to mount a file with docker-compose

查看:278
本文介绍了无法使用docker-compose挂载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行docker-compose -f docker-compose.prod.yml up,我立即收到错误消息:

I run docker-compose -f docker-compose.prod.yml up and I immediately get the error:

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工具箱进行开发.

My mysite.template file exists. I am using digital ocean with docker-machine. In development I didn't have this issue running on the same OS (ubuntu 16). I use docker toolbox on windows for development.

这是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"

我遵循了文档中的说明.任何想法出了什么问题吗?

I followed the instructions from the docs. Any ideas what's going wrong?

推荐答案

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

You can only mount host directories as volumes, and not individual files in Docker.

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

In your volumes definition, instead of this: - ${PWD}/frontend/conf/nginx/mysite.template:/etc/nginx/conf.d/default.conf

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

you should do this: - ${PWD}/frontend/conf/nginx:/etc/nginx/conf.d

这篇关于无法使用docker-compose挂载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆