Unable to mount a file with docker-compose
10,518
You can only mount host directories as volumes, and not individual files in Docker.
In your volumes
definition, instead of this:
- ${PWD}/frontend/conf/nginx/mysite.template:/etc/nginx/conf.d/default.conf
you should do this:
- ${PWD}/frontend/conf/nginx:/etc/nginx/conf.d
Author by
BugHunterUK
Updated on June 06, 2022Comments
-
BugHunterUK almost 2 years
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
My
mysite.template
file exists. I am using digital ocean withdocker-machine
. In development I didn't have this issue running on the same OS (ubuntu 16). I use docker toolbox on windows for development.Here's the frontend config from
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?
-
BugHunterUK over 5 yearsThis worked. Thank you. Does
${PWD}/frontend/public:/var/www/html
put the contents ofpublic/
intohtml/
? A little confusing. -
Alex almost 4 yearsThank you - i wasted so many hours trying to solve this. Your directory vs file point is vital in order to get this working correctly.