in case you haven't docker installed, please follow this instruction https://docs.docker.com/engine/install/ubuntu/
CreateΒ daemon.jsonΒ file inΒ /etc/docker, with content:
{"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]}
Second way suggested by @maireadmccabe-fire
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo vim /etc/systemd/system/docker.service.d/override.conf
# add the below to the override.conf file
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.socksudo systemctl daemon-reload and then sudo systemctl restart docker
or
sudo service docker restart
or just restart WSL2 by calling wsl --shutdownΒ in windows CMD/PowerShell and just open linux terminal once again
if you have run docker as sudo dockerd - stop it, and run sudo dockerd once again.
after restart docker daemon or restart wsl, run in linux terminal netstat -nl | grep 2375 (install net-tools if you haven't it). You should see that port are open.
add the following properties in Windows Env Variables:
| Name | Value |
|---|---|
| DOCKER_HOST | tcp://localhost:2375 |
| DOCKER_TLS_VERIFY | 0 |
| DOCKER_CERT_PATH | \\wsl$\home\$USER_NAME\.docker |
tcp://localhost:2375 should be replaced with tcp://$wsl_ip:2375, where $wsl_ip is IP of ifconfig eth0
βοΈ There is a workaround suggest by @tacascer
@echo off
set port=:2375
set
(for /f "tokens=2" %%f in ('wsl ifconfig eth0 ^| findstr /c:"inet "') do (
set dockerhost=tcp://%%f%port%
))
@REM echo %dockerhost%
setx DOCKER_HOST %dockerhost%DOCKER_HOST variable must be same as exposed above
$USER_NAME -replace this placeholder with your linux user
.testcontainers.properties - were empty
To apply environment variables you need restart IDE (in my case is Intellij Idea) OR just specify in Run/Debug Configuration these env variables directly.
If you are looking for secure access to docker follow the guide suggested by @gim-
Thanks for sharing, it helped me a lot to solve the problem, but that alone was not enough. I got more information and managed to solve it by following the steps: https://gist.github.com/jordisilvazup/a2863c06399c4f00940fa933772d426a