Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker for Windows and WSL1 to Work together

Exactly the same problem as Ubuntu WSL with docker could not be found

$ docker

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

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

But my requirement is different -- I want to

  • stick with WSL1 (for reasons beyond this topic)
  • and use Docker for Windows as-is

I.e., I have WSL1 and Docker for Windows installed parallel to each other. This is my current info:

C:> ver
Microsoft Windows [Version 10.0.18363.1379]

C:> wsl -l -v
  NAME      STATE           VERSION
* Debian    Running         1

I don't see integration in "Resources -> WSL Integration", and I don't have WSL2 backend enabled in Docker Desktop settings.

enter image description here

Just that I'm getting the above problem -- my docker works anywhere, in CMD, Powershell, git-bash, etc, just not in my WSL.

All solutions that I found are to install Docker for Windows within WSL1 or WSL2, but I want to keep everything as is -- WSL and Docker for Windows installed parallel to each other.

Any solution for that?

like image 470
xpt Avatar asked Mar 03 '21 23:03

xpt


People also ask

Can I use Docker with WSL1?

Use docker for windows in WSL1 (!) note: this applies only to WSL1. In WSL2 you can install docker and be happy — just use the official way of installing. Expose the docker client api without tls (there is a setting in Docker Desktop to do that) Now docker ps should already work. Install docker-compose and go for it.

Can you run Windows and Linux Docker containers at the same time?

Run Docker for Windows in “mixed” mode by running Windows and Linux containers together. I recently learned that I could turn on experimentally features in Docker for Windows and run both Windows and Linux images simultaneously. Normally we need to switch between them, and you can run one or the other.

Can I run Docker Desktop and VirtualBox?

First, VirtualBox 6 has an 'experimental' support for Hyper‑V. Second, the upcoming Windows Subsystem for Linux version 2 fully supports docker using Hyper‑V, even on Windows Home edition. Windows Subsystem for Linux (WSL) is really great for developers who want to install Windows on their PC.

Can Docker client and daemon run on different systems?

The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon.

Can the WSL be used with Docker for Windows?

With a couple of tweaks the WSL (Windows Subsystem for Linux, also known as Bash for Windows) can be used with Docker for Windows. Quick Jump: Configure Docker for Windows (Docker Desktop) | Install Docker and Docker Compose within WSL | Configure WSL to Connect to Docker for Windows | Ensure Volume Mounts Work This post only applies to WSL 1!

Is it possible to run Docker-daemon in WSL1?

Otherwise, the docker daemon is running in Hyper-V machine. But, if you stick in WSL1, no chance to run docker-daemon in WSL, so the only option is running docker daemon in Hyper-V machine.

How to integrate WSL2 backend engine with Docker?

To do this, select Settings from the menu and activate WSL2 backend engine on the General tab. After applying these actions, you will need to reboot the Docker application and then confirm the activation of WSL integration for Docker Desktop.

How to install Docker desktop on Windows?

Install 🔗 Follow the usual installation instructions to install Docker Desktop. If you are running a supported system, Docker... Start Docker Desktop from the Windows Start menu. From the Docker menu, select Settings > General. Select the Use WSL 2 based engine check box. If you have installed ...


1 Answers

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

This means in WSL2, it has a real linux kernel which is required to install docker daemon, then in docker-desktop you could have chance to set docker daemon in WSL2. Otherwise, the docker daemon is running in Hyper-V machine. But, if you stick in WSL1, no chance to run docker-daemon in WSL, so the only option is running docker daemon in Hyper-V machine.

Although above is the fact, still we have chance to let you operate docker ps, docker pull etc. in WSL1 bash just like you operate through CMD, Powershell, git-bash, that is allow Docker to accept requests from remote hosts.

For your case, the steps maybe next:

1. Expose docker daemon in docker desktop settings as next, then click Apply & Restart:

enter image description here

2. Install standalone docker client in WSL1:

$ wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz
$ tar zxvf docker-20.10.5.tgz
$ cd docker

3. Set default docker daemon:

$ export DOCKER_HOST=tcp://localhost:2375

4. Verify docker client command:

$ ./docker info
like image 153
atline Avatar answered Oct 28 '22 11:10

atline