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.

  • How to connect Cassandra and Node application in docker?
  • Golang: go build failing when called as part of makefile
  • How to solve “Rather than invoking init scripts…” on Ubuntu 14
  • How to run linux command before starting up git bash terminal
  • Consul not deregistering zombie services
  • AutoScaling in Docker Containers
  • 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

  • How to remove docker images based on name?
  • Docker mysql host not privileged
  • maven plugin for docker (e.g. to run with needed db)
  • Getting error installing nodejs when building from docker
  • Run Go script inside Docker Container or cron job?
  • Mac OS X & Docker 1.9.1 Insecure registry location
  • 2 Solutions collect form web for “Docker compose – share volume Nginx”

    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.

    You have to set a command to copy your nginx.conf into the nginx container:

    Dockerfile:

    FROM nginx
    COPY nginx.conf /etc/nginx/nginx.conf`
    

    Creat a dir name it nginx and put the Dockerfile & nginx.conf there, then you have to set a build:

    docker-compose.yml:

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

    Then build your containers with : sudo docker-compose build

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.