4

I've recently installed Ubuntu 22.04 WSL on my Windows 10 PC.
My naive understanding is that this Ubuntu "app" is equivalent to a Linux development environment.
When I explore within the running Ubuntu app, it generally feels like the normal Linux I'm accustomed to: the shell appears to be bash, and I have access to executables like git, curl, man, etc.

Trusting this claim that this Ubuntu WSL is equivalent to a Linux development environment, I now want to run Docker in this Ubuntu instance.
My naive understanding is that "since Linux natively supports containers, I should install Docker Engine" on Linux.
So I followed the steps described here: https://docs.docker.com/engine/install/ubuntu/
But when I try to verify that Docker Engine is installed correctly by running the hello-world image, I get the following error:

$ sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

There is no /var/run/docker.sock and I don't think the Docker daemon is running:

$ ls -l /var/run/docker.sock
ls: cannot access '/var/run/docker.sock': No such file or directory
$ ps aux | grep containerd
user    10212  0.0  0.0   8164   732 pts/2    S+   21:44   0:00 grep --color=auto containerd

Can someone please help me understand what has gone wrong, and if there is corrective action I can take to successfully install Docker in this Ubuntu WSL app on my Windows PC?

Perhaps are the instructions at https://docs.docker.com/engine/install/ubuntu/ only meant for "Ubuntu natively installed on a host PC" and not for Ubuntu WSL running on a Windows PC?

If so, then is there some other way I should be "installing Docker" so that Docker commands like sudo docker run hello-world can be run from within my Ubuntu WSL?

I'm quite confused by all the layers of software involved here.

2
  • Are you using WSL 1 or 2? Check with wsl -l -v. // WSL does not use service manager, so it won't start services like the Docker Daemon. Check a WSL-targeted guide.
    – Daniel B
    Commented Jul 28, 2022 at 5:23
  • @DanielB - it is WSL 2.
    – StoneThrow
    Commented Jul 28, 2022 at 18:36

2 Answers 2

4

My naive understanding is that this Ubuntu "app" is equivalent to a Linux development environment.

It's actually more like running Ubuntu in a container, because it really is. When running Ubuntu in a container (e.g. a Docker Ubuntu container), there are differences in how you set up services when compared to a physical or virtual machine. For instance, there's no Systemd running by default in a Docker Ubuntu container. There's no "login", and thus no PAM.

I've attempted to write up as many differences and limitations as I can think of in this Ask Ubuntu answer.

"since Linux natively supports containers, I should install Docker Engine" on Linux.

...

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

First, for most users, the recommended way of installing Docker in Windows/WSL2 is via Docker Desktop for Windows.

I cover some reasons why this is preferable in this Stack Overflow answer.

While it is possible to install and run Docker Engine manually in a WSL2 instance, there's one critical difference there that I explain in this answer. In short, the Docker Engine package under Ubuntu attempts to start the daemon via Systemd, which (as mentioned above) isn't running by default on WSL. On Ubuntu under WSL2, you need to first start the daemon with:

sudo service docker start

Updated:

You can now also utilize Systemd on WSL2 if desired to use the "documented" method. While I still prefer running without Systemd whenever possible on WSL2, there are definitely times when it can make life easier.

To enable, see the information in my answer here. Most recent WSL installations will have support built-in, but if you need to upgrade Windows or WSL, the instructions for that are in the post as well.

If you want to go this route, I do recommend that you enable Systemd before going through the Docker installation process linked in the question. With Systemd already running at the time of Docker install, it will automatically run and enable the service.

If you enable Systemd after installing Docker, you can run either:

sudo systemctl enable docker

... to have Docker automatically start when Ubuntu/WSL2 starts.

And/or:

sudo systemctl start docker

to start it in place of the service command.

9
  • "the Docker Engine package under Ubuntu attempts to start the daemon via Systemd, which...isn't running by default on WSL": Systemd and SystemV init are the two (competing?) programs whose job is to "dispatch processes" given some form of init script (e.g. init.d scripts and .service files) -- true? So do you mean that Ubuntu WSL has chosen SystemV as its "process dispatcher"? And the docker engine install doesn't "work with" the SystemV mechanism to start containerd?
    – StoneThrow
    Commented Jul 28, 2022 at 22:45
  • 1
    I wouldn't say that "Ubuntu WSL has chosen SysV", but that some Ubuntu packages (even on "real" Ubuntu) still provide SysVInit scripts (which run easily even without a SysV "boot"). That's good for WSL, since it doesn't (easily) have Systemd support. For instance, in Ubuntu, for cron, there's both a Systemd unit file and a SysV script. The same for Docker. However, some packages don't continue to provide the legacy SysV scripts. On RPM-based distros, I believe you'll find even fewer SysV scripts. The WSL openSUSE Tumbleweed distro, for instance, has no /etc/init.d at all. Commented Jul 28, 2022 at 22:54
  • 1
    Also recommend reading my Systemd doesn't work on Ubuntu/WSL deep-dive answer on Ask Ubuntu. Commented Jul 28, 2022 at 22:55
  • 1
    @StoneThrow No worries, but we may want to take this over to chat at some point. I'd recommend maybe the Ask Ubuntu General Room. But let me say it slightly differently for clarity -- The Docker package itself comes with both Systemd unit files and a legacy SysV init script. However, the package install script assumes that it is running on a Systemd system and uses systemctl enable docker (to make it run at boot) and systemctl start docker (to make it run in the current boot). Neither of those commands work on WSL. Commented Jul 28, 2022 at 23:14
  • 1
    @NotTheDr01ds you are right, thanks for the follow-up.
    – fgiraldeau
    Commented May 24, 2023 at 23:57
-2

First of all check docker logs: sudo cat /var/log/docker.log

in case of: failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to register "bridge" driver: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain: (iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1.8.7 (nf_tables): RULE_APPEND failed (No such file or directory): rule in chain DOCKER-ISOLATION-STAGE-1 (exit status 4))

use this:

sudo update-alternatives --config iptables Enter 1 to select iptables-legacy and run sudo service docker start and Docker should start as expected.

If it is still not the problem maybe this site will be useful: https://dataedo.com/docs/installing-docker-on-windows-via-wsl

2
  • 1
    You have some useful information here, I believe, but it's not an answer to this question. You should post the problem as it's own question and then self-answer with your solution. Thanks! Commented Apr 9 at 15:43
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Commented Apr 9 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .