Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shared drive mounts inside /mnt #860

Closed
marfillaster opened this issue Jun 29, 2017 · 3 comments
Closed

Add shared drive mounts inside /mnt #860

marfillaster opened this issue Jun 29, 2017 · 3 comments

Comments

@marfillaster
Copy link

marfillaster commented Jun 29, 2017

Expected behavior

PS C:\Users\me> bash
/mnt/c/Users/me$ touch test.txt
/mnt/c/Users/me$ [ -f "text.txt" ] &&  echo 1 || echo 0
1
/mnt/c/Users/me$ export DOCKER_HOST=tcp://127.0.0.1:2375
/mnt/c/Users/me$  docker version
Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Mon Mar 27 17:14:09 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:51:55 2017
 OS/Arch:      linux/amd64
 Experimental: true

/mnt/c/Users/me$ docker run -rm -v$(pwd):/var/tmp -it ubuntu \
/bin/bash  [ -f "text.txt" ] &&  echo 1 || echo 0
1

Actual behavior

/mnt/c/Users/me$ docker run -rm -v$(pwd):/var/tmp -it ubuntu \
/bin/bash  -c '[ -f "/var/tmp/text.txt" ] &&  echo 1 || echo 0'
0

/mnt/c/Users/me$ docker run -rm -v./:/var/tmp -it ubuntu \
/bin/bash  -c '[ -f "/var/tmp/text.txt" ] &&  echo 1 || echo 0'
0

/mnt/c/Users/me$ docker run -rm -v$/mnt/c/Users/me:/var/tmp -it ubuntu \
/bin/bash  -c '[ -f "/var/tmp/text.txt" ] &&  echo 1 || echo 0'
0

/mnt/c/Users/me$ docker run -rm -v/c/Users/me:/var/tmp -it ubuntu \
/bin/bash  -c '[ -f "/var/tmp/text.txt" ] &&  echo 1 || echo 0'
1

As you can see, using pwd is not ideal. But if in moby /c is also available in /mnt/c, working with docker in wsl is going to be more fun.

@beiriannydd
Copy link

beiriannydd commented Jun 30, 2017

In the meantime you might like to install this in /usr/local/bin/docker and hash -r (assuming that /usr/local/bin is earlier in your path than /usr/bin, and docker is in /usr/bin which it is in my default wsl install). The other thing this shim does is add an extra leading / to non /mnt paths which seems to be necessary to properly have them interpreted as "from the linux VM"

#!/bin/bash
cmd=()
stripmount=0
for arg in "$@"; do
  if [ "$stripmount" -eq 1 ]; then
    new="${arg//\/mnt/}"
    if [ "$new" = "$arg" ]; then
      arg="/$arg"
    else
      arg="$new"
    fi
    stripmount=0
  fi
  case "$arg" in
    -v|-w)
        stripmount=1
        ;;
  esac
  cmd+=("$arg")
done
exec /usr/bin/docker "${cmd[@]}"

@marfillaster
Copy link
Author

Insider build 17093 has introduced a way of mounting to a custom root directory.

[automount]
root = /host_mnt/

Using docker-ce 17.12.0-ce-win47 and the new wsl root, $(pwd -P) is now usable for -v mapping.

@docker-robott
Copy link
Collaborator

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 docker locked and limited conversation to collaborators Jun 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants