Is Docker running within WSL or connecting back to Windows?

风格不统一 提交于 2019-11-30 19:46:07

The Docker daemon can't run under WSL as it doesn't implement the necessary kernel ABI's. If you're running Docker for Windows, you are probably connecting to the Hyper-V virtual machine that it manages.

Because it's on a different machine, you will not be able to mount WSL directories as Docker volumes, but you can build images from a WSL directory. This is because on a build, the client creates a tarball and sends it to the daemon.

This is a workaround which is to use Docker on windows in WSL instead.

Just add the following to your WSL .bashrc file.

export PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export PATH="$PATH:/mnt/c/Program\ Files/Docker/Docker/resources/bin"
alias docker=docker.exe
alias docker-compose=docker-compose.exe

Reference: https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/

As other answers stated, Docker can't be installed and hosted inside WSL but can be used directly from there as any Windows executable.

It may only require an extra effort to make it usable without those pesky .exe extensions: Bash on Windows - alias for exe files. The linked workaround provides a ready to use custom script for easy symlink creation. Symlinks can be freely used inside non-interactive shell scripts unlike bash aliases.


There is also an approach with connecting from WSL to Docker for Windows as remote host described in https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly.

If you’re wondering “why not just run docker.exe and docker-compose.exe from Docker for Windows directly in WSL?”, that’s due to a bug with running Docker or Docker Compose interactively in that environment. The TL;DR is you can’t run anything in the foreground with interactive mode, which makes it unusable for real web development.

But sadly there is no reference to exact bug symptoms there. And I didn't face it so far.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!