4

I work on WSL on Windows. I downloaded Ubuntu 20.04 from the Microsoft Store. After running, I ran these commands:

sudo apt update
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7EA0A9C3F273FCD8
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce
sudo systemctl start docker
sudo docker run hello-world

Unfortunately:

$ sudo systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

and:

$ 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'.

What do I need to do to get docker working on my WSL? My co-worker used identical commands and everything worked for him

1

2 Answers 2

3

There are at least three possible solutions here:

  • First, as @ArturMeinild mentioned in the close-vote/comments, the core issue here is that sudo systemctl start docker assumes that you are running Systemd. By default, in Ubuntu 20.04 and 22.04, Systemd is not enabled on WSL. I believe this is supposed to change in 24.04, but I still typically recommend running without Systemd (as mentioned in my answer to the question linked by @ArturMeinild).

    Your colleague likely has Systemd enabled.

  • Second, it's quite easy to run Docker without Systemd using sudo service docker start. See this Stack Overflow answer as well for explanation and details.

  • Finally, as mentioned in that last linked answer, I personally recommend using Docker Desktop instead of the open-source Docker Engine here. I have no ties with Docker, but I believe there are many good reasons to use Docker Desktop, even if it would require a license for your company:

    • It automatically handles the start-up in WSL and would have prevented you from running into this problem in the first place. That alone would have certainly saved your employer more (in your time troubleshooting this) than the cost of the license.

    • Supporting Docker through a license purchase (if needed) is good business as well, as it helps fund the development.

    • There is a lot of value-add in Docker Desktop that will likely make you more productive overall. See my Stack Overflow answer for a list of features that Docker Desktop provides that Docker Engine does not.

1

In addition to the (excellent) answer by NotTheDr01ds, you can also run the Docker daemon directly. The command dockerd does that, so you could run sudo dockerd in another WSL window/tab

tmux is another way that can work. If you don't mind sending all the dockerd output into a file (that you may want to check to ensure it works), you could do this:

$ sudo dockerd > ~/dockerd-log.txt 2>&1 &
[1] (the PID of dockerd)

$ sudo docker run hello-world
...

You probably could also substitute ~/dockerd-log.txt for /dev/null if you are happy to discard the output.

You must log in to answer this question.

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