DamionGans / ubuntu-wsl2-systemd-script

[Does not work anymore!] Script to enable systemd support on current Ubuntu WSL2 images
1.56k stars 383 forks source link

Docker WSL2 not accessible from within WSL2 Ubuntu-20.04 #18

Closed ad-on-is closed 4 years ago

ad-on-is commented 4 years ago

I've run the script and snapworks, but docker does not. I'm running WSL 2 with Ubuntu 20.04 and I'm using Windows terminal.

When I do docker ps, I get the error docker command not found

Although, when I open VSCode Remote-Extension and type docker ps in the VSCode terminal, Docker works there.

Inspecting ps -ef on both, VSCode and Terminal, gives me:

VSCode: root 1 0 0 13:16 ? 00:00:00 /init Terminal: root 1 0 0 13:16 ? 00:00:00 /lib/systemd/systemd --system-unit=basic.target

Both env-variables are set

cmd.exe /C setx WSLENV BASH_ENV/u
cmd.exe /C setx BASH_ENV /etc/bash.bashrc

Is this scenario even supposed to work with systemd enabled?

Cheers,

blackliner commented 4 years ago

I got docker to work (used docker edge desktop and connected/disconnected it a few times in the resource settings 🤷 ), but then i have problems with user id's passing through to the docker image... Maybe the docker WSL2 impl does not like systemd?

DamionGans commented 4 years ago

I have tried using docker in Ubuntu WSL2 with the systemd hack enabled as well and indeed it does not work. I get the following error message:

The command 'docker' could not be found in this WSL 2 distro.
We recommend to activate the WSL integration in Docker Desktop settings.

See https://docs.docker.com/docker-for-windows/wsl/ for details.

That's something we can look into...

stealthybox commented 4 years ago

The systemd namespace cannot see most files in the docker-desktop WSL 2 container. It can only list the top-most directories.

I'm not sure how access is controlled but it could be UNIX file permissions, mounts, or a linux security module.

To reproduce, comment out the start-systemd-namespace line near the top of your /etc/bash.bashrc to load into a working WSL 2 shell:

stealthybox:~$ ls /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker
/mnt/wsl/docker-desktop/cli-tools/usr/bin/docker

stealthybox:~$ find /mnt/wsl/docker-desktop/ | wc -l
239

stealthybox:~$ /usr/sbin/start-systemd-namespace
Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.19.104-microsoft-standard x86_64)
Last login: Wed Jun 17 12:35:21 MDT 2020 on pts/0

stealthybox:~$ ls /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker
ls: cannot access '/mnt/wsl/docker-desktop/cli-tools/usr/bin/docker': No such file or directory

stealthybox:~$ find /mnt/wsl/docker-desktop/ | wc -l
6

stealthybox:~$ exit
logout

stealthybox:~$ ls /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker
/mnt/wsl/docker-desktop/cli-tools/usr/bin/docker

stealthybox:~$ find /mnt/wsl/docker-desktop/ | wc -l
239
ad-on-is commented 4 years ago

I found that https://github.com/diddledan/ubuntu-wsl2-systemd-script works expected

Yiyiyimu commented 4 years ago

I found that https://github.com/diddledan/ubuntu-wsl2-systemd-script works expected

Hi @ad-on-is It seems Daniel's repo stays the same with main repo, and in my test docker still not working with code in Daniel's repo. Did you edit some parts to make it work?

ad-on-is commented 4 years ago

I found that https://github.com/diddledan/ubuntu-wsl2-systemd-script works expected

Hi @ad-on-is It seems Daniel's repo stays the same with main repo, and in my test docker still not working with code in Daniel's repo. Did you edit some parts to make it work?

No, I did not, I just ran the script and forced the re-installation.

Yiyiyimu commented 4 years ago

No, I did not, I just ran the script and forced the re-installation.

Thank you for your reply! It seems my environment got some problems. I've already changed from docker to containerd, and that works well.

srini1978 commented 4 years ago

I couldnt get docker running either