Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose - share volume Nginx

I just want to test Docker and it seems something is not working as it should. When I have my docker-compose.yml like this:

web:
  image: nginx:latest
  ports:
    - "80:80"

when in browser I run my docker.app domain (sample domain pointed to docker IP) I'm getting default nginx webpage.

But when I try to do something like this:

web:
  image: nginx:latest
  volumes:
    - /d/Dev/docker/nginx-www/nginx/html/:/usr/share/nginx/html/ 
  ports:
    - "80:80"

when I run:

docker-compose up -id

when I run same url in browser I'm getting:

403 Forbidden

nginx/1.9.12

I'm using Windows 8.1 as my host.

Do I do something wrong or maybe folders cannot be shared this way?

EDIT

Solution (based on @HemersonVarela answer):

The volume I've tried to pass was in D:\Dev\docker location so I was using /d/Dev/docker at the beginning of my path. But looking at https://docs.docker.com/engine/userguide/containers/dockervolumes/ you can read:

If you are using Docker Machine on Mac or Windows, your Docker daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory.

so what I needed to do, is to create my nginx-ww/nginx/html directory in C:\users\marcin directory, so I ended with:

web:
  image: nginx:latest
  volumes:
    - /c/Users/marcin/docker/nginx-www/nginx/html/:/usr/share/nginx/html/ 
  ports:
    - "80:80"

and this is working without a problem. Files are now shared as they should be

like image 573
Marcin Nabiałek Avatar asked Mar 14 '16 18:03

Marcin Nabiałek


1 Answers

If you are using Docker Machine on Windows, docker has limited access to your Windows filesystem. By default Docker Machine tries to auto-share your C:\Users (Windows) directory.

So the folder .../Dev/docker/nginx-www/nginx/html/ must be located somewhere under C:\Users directory in the host.

All other paths come from your virtual machine’s filesystem, so if you want to make some other host folder available for sharing, you need to do additional work. In the case of VirtualBox you need to make the host folder available as a shared folder in VirtualBox.

like image 64
Hemerson Varela Avatar answered Sep 18 '22 14:09

Hemerson Varela