docker / for-win

Bug reports for Docker Desktop for Windows
https://www.docker.com/products/docker#/windows
1.86k stars 289 forks source link

Interoperability with Ubuntu bash for windows #371

Open wclr opened 7 years ago

wclr commented 7 years ago

It is possible to install docker/docker-compose in lightweight Ubuntu for windows and interact with docker for windows docker host, so it works quite ok.

The problem is that ubuntu for windows mounts drives into /mnt (/mnt/c, /mnt/d) and in MobyLinuxVM drives a mount into / (/c, /d), to make it possible to attach/map volumes in ubuntu bash shell current workaround is to make symlinks ln -s /d /mnt/d, after this it works fine.

So for interability with Ubuntu bash for windows I believe it would be reasonable to mount drives in MobyLinuxVM into /mnt (instead of /) by default.

PetaPetaPeta commented 7 years ago

@whitecolor I can't seem to make the ln -s /d /mnt/d to work correctly. I still get the error: ERROR: build path /mnt/c/... either does not exist, is not accessible, or is not a valid URL. Do you do anything else to make it work?

wclr commented 7 years ago

@PetaPetaPeta does the link you created indied MobyLinuxVM works ok? First you should mkdir -p /mnt

Btw there is a problem with this workaround that every time docker engine restarts (for example on system reboot) it restores original MobyLinuxVIM image,, so you have to execute commands for liks again (I execute some cli file after each docker start manually which is kind of clumsy but works for me). I think there is another option I didn't try yet that, try to make links in Ubuntu for bash /mnt/d --> /d and see how it works.

wclr commented 7 years ago

Have you considered this yet?

aseering commented 7 years ago

Just for clarity: This ticket is specifically referring to Microsoft's "Bash on Windows" / "Windows Subsystem for Linux" feature.

Using this feature, it's possible (indeed, easy -- simply open up a Windows Command Prompt, type bash, and type sudo apt install docker.io) to install and run the Ubuntu Linux Docker command-line binary natively on a Linux machine. Because the Linux binary is running natively, therefore sharing the Windows TCP stack, it's very easy to point the Linux Docker binary at the Docker for Windows server.

However, if you do so, as discussed above, docker -v is broken because Windows paths are mapped differently in the Docker for Windows VM and the Windows Subsystem for Linux.

wclr commented 7 years ago

The appropriate workaround would be to insert in your .bashrc:

docker run --rm -i --privileged --network=none --pid=host justincormack/nsenter1 /bin/sh -c "mkdir -p /mnt;drives="c d e f g"; for l in $drives; do if [[ -d $l ]] && [[ ! -d /mnt/$l ]]; then  ln -s /$l mnt/$l; fi; done"

This will do the proper mapping inside Moby Linux VM

copitz commented 7 years ago

@whitecolor This didn't work for me :(

Instead I have the following in my .bashrc:

# mount /mnt/c to /c if not already done
if [ ! -d "/c" ] || [ ! "$(ls -A /c)" ]; then
  echo "Requiring root password to $(tput setaf 6)mount --bind /mnt/c /c$(tput sgr 0)"
  sudo mkdir -p /c
  sudo mount --bind /mnt/c /c
fi

# Change from /mnt/c/... to /c/...
if [ "$(pwd | cut -c -7)" == "/mnt/c/" ]; then
  cd "$(pwd | cut -c 5-)"
fi

# Provide docker for bash and docker-compose
docker() {
  docker.exe "$@"
}

I tried docker-ce installed in bash with the mount solution which works in general but not for symlinks created from within the mounts. Thus I removed docker-ce and added an alias for docker instead.

docker-robott commented 6 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale comment. Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

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

joshrickert commented 6 years ago

This feature would still be very useful. It's the main reason I haven't been able to move my workflow over to WSL. /remove-lifecycle stale

edmorley commented 6 years ago

The docker-for-desktop-robot has removed the lifecycle/stale label, however the issue is still closed. Could someone reopen it please? :-)

rn commented 6 years ago

the robot closed it because the label was not removed within 30 days (it was only removed after). the robot does not look at closed issues...

docker-robott commented 6 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale comment. Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

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

edmorley commented 6 years ago

/lifecycle frozen

edmorley commented 6 years ago

/remove-lifecycle stale

ohartl commented 5 years ago

FYI: You can just change the root to / instead of /mnt in the /etc/wsl.conf, close & open terminal and it should be "automounted" in the correct path

[automount]
root = /

https://blogs.msdn.microsoft.com/commandline/2018/02/07/automatically-configuring-wsl/

dwheeler commented 5 years ago

FYI: You can just change the root to / instead of /mnt in the /etc/wsl.conf

This causes a number of other wsl compatibility issues where other programs have made the assumption that wsl has mounted c to /mnt/c. It's not really a long term solution, just flips around where things break.

sgtoj commented 5 years ago

@dwheeler Suggestion... Try configuring wsl.conf with root = / and mountFsTab = true. Update the fstab file to link the new location to the old location (i.e. by adding /c /mnt/c none bind to the file).

If you do not want to use the wsl.conf, you can use my old method that shared on gist.