for-win icon indicating copy to clipboard operation
for-win copied to clipboard

bind mounting of a mounted host directory in a container is broken in v.2.3.0.2

Open aliaugmenta opened this issue 6 years ago • 12 comments

  • [ x] I have tried with the latest version of my channel (Stable or Edge)
  • [ ] I have uploaded Diagnostics
  • Diagnostics ID:

Expected behavior

Just before updating to v.2.3.0.2 I was able to mount any directory in a container and inside that container mount the same host directory into another container.

Actual behavior

Content of the host directory is not accessible OR is incomplete when the directory is mounted in a container inside another container.

Information

  • Is it reproducible? YES

  • Is the problem new? YES

  • Did the problem appear with an update? YES

  • A reproducible case if this is a bug, Dockerfiles with reproduction inside is best.

  • Windows Version: 10.0.18363.815

  • Docker Desktop Version: v.2.3.0.2

  • Windows Version:
  • Docker Desktop Version: 2.3.0.2 (45183)
  • Are you running inside a virtualized Windows e.g. on a cloud server or on a mac VM: NO

Steps to reproduce the behavior

  • Mounting C::
docker run -it  -v /var/run/docker.sock:/var/run/docker.sock -v /C/:/w -w /w ubuntu:20.04

Check if C: is mounted properly: pwd && ls Now, mount /C in another container

root@66896a0d8f2c:/w#  apt-get update && apt-get install -y docker.io

root@66896a0d8f2c:/w#  docker run -it  -v /C:/w -w /w ubuntu bash -c  'pwd && ls -l'
**/w
total 0
drwxr-xr-x 3 root root 60 May 11 15:42 Users

BUG: Mounding /C into another counter does not work properly! the second container only sees "C:\Users"!

  • Mounting C:\temp:
docker run -it  -v /var/run/docker.sock:/var/run/docker.sock -v /C/temp:/w -w /w ubuntu:20.04

Check if C:\temp is mounted properly: pwd && ls Now, mount /C/temp in another container

root@66896a0d8f2c:/w#  apt-get update && apt-get install -y docker.io
root@66896a0d8f2c:/w#  docker run -it  -v /C/temp:/w -w /w ubuntu bash -c  'pwd && ls -l'
/w
**total 0**

BUG: None of the files or directories in c:\temp will be displayed!

aliaugmenta avatar May 11 '20 17:05 aliaugmenta

Thanks for your report. Inside your ubuntu container could you try using a different path? Let me know if this works better: (with /host_mnt/C rather than /C):

docker run -it -v /host_mnt/C:/w -w /w ubuntu bash

djs55 avatar May 11 '20 17:05 djs55

Thank you @djs55 . Yes! it works with /host_mnt prefix . When I mount c:\temp in the first container, I can mount both C: and C:\temp into the second container successfully.

Is this issue a bug? or an expected change?

aliaugmenta avatar May 11 '20 18:05 aliaugmenta

Had the same issue with some mounted containers in Kubernetes. Prefixing with /host_mnt seems to have fixed it.

However this is going to be a challenge, have multiple developers using a combination of Docker Desktop with hyper v and Minikube with virtualbox. Up until now, the host mounting path has been the consistent on both platforms at /c. Is there a way to tell which version of Docker desktop is running from a powershell terminal so I can change the mount path to /host_mnt/c on just Docker desktop version 2.3.0+ ? docker version cmd doesn't seem to contain any information about Docker Desktop version running.

Etna-mhoskison avatar May 11 '20 20:05 Etna-mhoskison

While the /host_mnt/ prefix does work, it looks like the file API notifications aren't getting passed in anymore. This is also as of 2.3.0.2.

In my particular example, I'm using Python and Django with the runserver which uses either pywatchman or pyinotify to interface the API.

Edit: This may need to be opened as a new issue. But does seem related. 😬

loganbibby avatar May 12 '20 15:05 loganbibby

I updated this morning to see if enough bugs had been fixed to let me use the 2.3.x.x branch, and found that I got an error when re-upping with docker-compose:

g-rath@DESKTOP-MUGH739:/c/Users/G-Rath/docktest$ docker-compose up
Creating network "docktest_default" with the default driver
Creating volume "docktest_my-app-vol" with local driver
Creating docktest_app_1 ... done
Attaching to docktest_app_1
app_1  | 2
docktest_app_1 exited with code 0
g-rath@DESKTOP-MUGH739:/c/Users/G-Rath/docktest$ docker-compose up
ERROR: Configuration for volume my-app-vol specifies "device" driver_opt /c/Users/G-Rath/docktest, but a volume with the same name uses a different "device" driver_opt (/host_mnt/c/Users/G-Rath/docktest). If you wish to use the new configuration, please remove the existing volume "docktest_my-app-vol" first:
$ docker volume rm docktest_my-app-vol

I found this while attempting to reproduce another bug, so have not yet compared it to the 2.1.x.x branch but my bet is it'll work since this is based on a docker compose project we have at work that has been around for a few good months, so @sp0rkie it sounds like this could all be because of the same issue.

This is my docker-compose file:

version: "3.5"
services:
  app:
    image: node:14
    labels:
      - "my-app"
    volumes:
      - my-app-vol:/var/www:nocopy
    command: ["node", "-p", "1+1"]
volumes:
  my-app-vol:
    driver: local
    driver_opts:
      type: none
      device: $PWD
      o: bind

Depending on my findings I may make a new issue, but wanted to post this here for initial visibility :)

G-Rath avatar May 13 '20 03:05 G-Rath

Is this issue a bug? or an expected change?

It’s a non documented implementation detail of how we handle the file sharing that we changed without realizing it would break a number of established use cases. We didn’t mean to break it and will be issuing a patch release in a few days.

Sorry for the inconvenience. In the meanwhile we have made a private build with a fix that you can try: https://download-stage.docker.com/win/stable/45279/Docker%20Desktop%20Installer.exe

Please let us know if this solves the issue for you. Thanks!

mat007 avatar May 15 '20 13:05 mat007

I had a similar issue where my development environment container mounted c:/:/c volume and sibling containers used --volumes-from the dev enviornment container. This 45279 build in the above link fixed the issue for me. Thanks for the support.

terryherron avatar May 16 '20 11:05 terryherron

In gitlab-runner volumes from my host computer aren't mount either. They are declared in config.toml. Putting /host_mnt in front of the volume path doesn't seem to work either. Does anyone have a workaround for this?

Before /c/Users/nicol/jwt:/etc/jwt After /host_mnt/c/Users/nicol/jwt:/etc/jwt

goevexx avatar May 19 '20 13:05 goevexx

After some testing on both versions 2.2.0.5 and 2.3.0.2, I found the following regarding bind volumes path formats:

  <= 2.2.0.5 == 2.3.0.2
C:\path\to\folder ❌fails ✔️works
C://path/to/folder ❌fails ✔️works
//C/path/to/folder ✔️works ❌fails
/C/path/to/folder ✔️works ✔️works
/host_mnt/c/path/to/folder ✔️works ✔️works

(notice the lowercase drive letter in the last format)

Based on the following test:

$ docker volume create --driver local --opt type=none --opt device=/host_mnt/c/path/to/folder --opt o=bind test_vol
test_vol
$ docker run --rm -v test_vol:/data alpine ls /data
file.txt

Furthermore, on 2.3.0.2, on inspecting the volume you will see that all compatible paths are transformed in the format /host_mnt/c/path/to/folder.

This means, in docker-compose, that if you use any other format and try to reuse an already created volume (i.e. two consecutive up), you get an error:

version: '3.4'

volumes:
   test_vol:
      driver: local
      driver_opts:
         type: none
         device: /C/path/to/folder
         o: bind

services:
  alpine:
    image: alpine:latest
    command: ls /data
    volumes:
       - test_vol:/data
$ docker-compose up
Creating network "test_default" with the default driver
Creating volume "test_test_vol" with local driver
Creating test_alpine_1 ... done
Attaching to test_alpine_1
alpine_1  | file.txt
test_alpine_1 exited with code 0
$ docker volume inspect test_test_vol
[
   {
       "CreatedAt": "2020-05-22T13:13:46Z",
       "Driver": "local",
       "Labels": {
           "com.docker.compose.project": "test",
           "com.docker.compose.version": "1.25.5",
           "com.docker.compose.volume": "test_vol"
       },
       "Mountpoint": "/var/lib/docker/volumes/test_test_vol/_data",
       "Name": "test_test_vol",
       "Options": {
           "device": "/host_mnt/c/path/to/folder",
           "o": "bind",
           "type": "none"
       },
       "Scope": "local"
   }
]
$ docker-compose up
ERROR: Configuration for volume test_vol specifies "device" driver_opt /C/path/to/folder, but a volume with the same name uses a different "device" driver_opt (/host_mnt/c/path/to/folder). If you wish to use the new configuration, please remove the existing volume "test_test_vol" first:
$ docker volume rm test_test_vol

So based on this, I would tend to use the /host_mnt/c/path/to/folder format, for cross-compatibility between versions and satisfactory workflow in docker-compose.

I have a couple questions though:

tnodet avatar May 22 '20 13:05 tnodet

The fix has now been released in Docker Desktop Stable 2.3.0.3, I’ll go ahead and close this issue.

mat007 avatar May 27 '20 18:05 mat007

Thank you for the fix 🙂

I did some more testing, here are the results:

path format  <= 2.2.0.5 == 2.3.0.2 == 2.3.0.3
C:\path\to\folder ❌fails ✔️works ✔️works
C://path/to/folder ❌fails ✔️works ✔️works
//C/path/to/folder ✔️works ❌fails ✔️works
/C/path/to/folder ✔️works ✔️works ✔️works
/host_mnt/c/path/to/folder ✔️works ✔️works ✔️works

Interestingly enough, in 2.3.0.3, if you inspect the volume (docker volume inspect):

path format at volume creation path format at volume inspection
C:\path\to\folder /host_mnt/c/path/to/folder
C://path/to/folder /host_mnt/c/path/to/folder
//C/path/to/folder /C/path/to/folder
/C/path/to/folder /host_mnt/c/path/to/folder
/host_mnt/c/path/to/folder /host_mnt/c/path/to/folder

Notice how the //C/path/to/folder path format is converted into /C/path/to/folder, contrary to the other path formats which are all converted into /host_mnt/c/path/to/folder.


So my conclusion in previous comment didn't change, I would tend to use the /host_mnt/c/path/to/folder format, for cross-compatibility between versions and satisfactory workflow in docker-compose.

It would be nice to update the documentation to specify best practices regarding path format of bind volumes on Windows hosts 🙂

tnodet avatar May 29 '20 10:05 tnodet

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle locked

docker-robott avatar Jul 16 '20 03:07 docker-robott