nginx-proxy icon indicating copy to clipboard operation
nginx-proxy copied to clipboard

Docker for Windows volume mounts and docker.sock

Open johnrom opened this issue 8 years ago • 9 comments

Mounting /var/run/docker.sock is no longer working in stable Docker for Windows with the latest update. There is an issue here: https://github.com/docker/for-win/issues/1829

I'm not sure whether the issue is that docker.sock file is no longer a reliable source for DFW, and if that is the case then the issue will have to be resolved here. However, if it's a bug and it should still be able to mount docker.sock on the Docker for Windows side of things, this bug should resolve itself in a future update.

An example error is here:

ERROR: for front  Cannot create container for service front: b'Mount denied:\nThe source path "\\\\var\\\\run\\\\docker.sock:/tmp/docker.sock"\nis not a valid Windows path'

Example docker-compose.yml:

front:
  restart: always
  image: jwilder/nginx-proxy
  volumes:
    - /var/run/docker.sock:/tmp/docker.sock
  ports:
    - "80:80"
    - "443:443"

Docker Version: 18.03.0-ce-win59

johnrom avatar Mar 26 '18 14:03 johnrom

There was a workaround found in docker/for-win#1829

Add an this environment variable: COMPOSE_CONVERT_WINDOWS_PATHS = 1

Or from Powershell run $Env:COMPOSE_CONVERT_WINDOWS_PATHS=1

a727891 avatar Mar 28 '18 13:03 a727891

I am still getting my mount error even after changing that value to 1.

BaileyMillerSSI avatar Oct 12 '18 04:10 BaileyMillerSSI

Error:

ERROR: for reverseproxy_nginx-proxy_1  Cannot create container for service nginx-proxy: b'Mount denied:\nThe source path "\\\\var\\\\run\\\\docker.sock:/tmp/docker.sock"\nis not a valid Windows path'

ERROR: for nginx-proxy  Cannot create container for service nginx-proxy: b'Mount denied:\nThe source path "\\\\var\\\\run\\\\docker.sock:/tmp/docker.sock"\nis not a
valid Windows path'
ERROR: Encountered errors while bringing up the project.

docker-compose.yml:

version: '2'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock

  whoami:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=www.whoamitest.com

BaileyMillerSSI avatar Oct 12 '18 05:10 BaileyMillerSSI

@BaileyMillerSSI , it's likely that the variable isn't being set during execution of the script. you can test this on Bash by doing something like:

COMPOSE_CONVERT_WINDOWS_PATHS=1 docker-compose up. Running the commands separately will not persist the value unless you use export COMPOSE_CONVERT_WINDOWS_PATHS=1.

My comment here is more thorough.

johnrom avatar Oct 12 '18 15:10 johnrom

I lean out of the window and say that everyone forgot an important point: /var/run/docker.sock does not exist on a windows system. You can't mount anything that does not exist. Even under Windows 10 with the Ubuntu Bash this file does not exist. The path would have to be adjusted but I'm not sure if windows ever created the docker.sock file or used.

padhie avatar Nov 11 '18 18:11 padhie

@padhie Linux Containers in Docker for Windows run within a vm under hyper-V. This VM is mapping its docker.sock to the nginx-proxy container.

This image runs in a Linux Container.

johnrom avatar Nov 13 '18 14:11 johnrom

@johnrom but you try an windows directory map and this isn't exists

padhie avatar Nov 13 '18 18:11 padhie

@padhie I think the misunderstanding is that setting this variable just happens to fix the problem by changing the way paths are parsed. It's not mapping this path to Windows in any way. This directory doesn't exist in Windows, it exists in the Hyper-V VM (Linux). Hopefully, this will help you understand. When you open Docker for Windows "Settings" and go to "Shared Drives", it helps you demonstrate the shared drive is working by entering this command:

docker run --rm -v c:/Users:/data alpine ls /data

What it then does, is automatically changes C:/Users to /c/Users in the background to demonstrate that C:\Users is correctly mounted within the Linux VM, and passed on to the container you create. What it doesn't tell you, is there is a way to prevent that from happening, and by doing that you can prove that you're actually mounting the drive from Linux to the Container. Using two slashes allows you to circumvent this conversion.

docker run --rm -v //:/data alpine ls //data

Now you'll see a Linux root directory, with folders like var, opt, etc.

docker run --rm -v //var/run:/data alpine ls //data

Now you'll see that there is a docker.sock

johnrom avatar Nov 14 '18 15:11 johnrom

I can confirm the workaround posted by @a727891 works, so I'm going to close this. Any further resolution wouldn't appear to be related to this repo.

johnrom avatar Nov 20 '18 18:11 johnrom