I want to connect to Docker TCP socket running in WSL2 via PyCharm. I can't seem to expose the socket, I think possibly because there's limited control of docker-daemon within WSL2 (systemctl)? I can't use Docker Desktop because I need GPU support (Windows Dev Channel + nvidia-docker). I've tried the following:
export DOCKER_HOST=tcp://0.0.0.0:2375
$ export DOCKER_HOST=tcp://0.0.0.0:2375
$ sudo service docker restart
$ docker context ls
NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default * Current DOCKER_HOST based configuration tcp://0.0.0.0:2375 swarm
Warning: DOCKER_HOST environment variable overrides the active context. To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.
$ curl --unix-socket /var/run/docker.sock http:/localhost/version
{"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"19.03.11","Details":{"ApiVersion":"1.40","Arch":"amd64","BuildTime":"2020-06-01T09:10:54.000000000+00:00","Experimental":"false","GitCommit":"42e35e61f3","GoVersion":"go1.13.10","KernelVersion":"4.19.121-microsoft-standard","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"containerd","Version":"1.2.13","Details":{"GitCommit":"7ad184331fa3e55e52b890ea95e65ba581ae3429"}},{"Name":"runc","Version":"1.0.0-rc10","Details":{"GitCommit":"dc9208a3303feef5b3839f4323d9beb36df0a9dd"}},{"Name":"docker-init","Version":"0.18.0","Details":{"GitCommit":"fec3683"}}],"Version":"19.03.11","ApiVersion":"1.40","MinAPIVersion":"1.12","GitCommit":"42e35e61f3","GoVersion":"go1.13.10","Os":"linux","Arch":"amd64","KernelVersion":"4.19.121-microsoft-standard","BuildTime":"2020-06-01T09:10:54.000000000+00:00"}
$ curl http://localhost:2375/version
curl: (7) Failed to connect to localhost port 2375: Connection refused
The final command I expect to give a result like {"Version":"17.05.0-ce","ApiVersion":"...}
but connection refused. Indeed, if I try to connect via Windows host Pycharm it refuses connection. I also see many tutorials / SO posts saying not to use this DOCKER_HOST approach, but I'm not sure why.
/lib/systemd/system/docker.service > ExecStart
Per stackoverflow, serverfault, ivankrizsan, I edited /lib/systemd/system/docker.service
with ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375
. But when I try systemctl daemon-reload
it errors; WSL2 doesn't support systemctl
commands (WSL/457).
$ sudo systemctl daemon-reload
System has not been booted with systemd as init system (PID 1). Can't operate.
I also tried restarting WSL2 (Powershell wsl --shutdown
, re-open WSL2) in case docker-daemon will pick those change up, but no cigar.
$ curl http://localhost:2375/version
curl: (7) Failed to connect to localhost port 2375: Connection refused
/etc/default/docker > DOCKER_OPTS
Per stackoverflow, I edited /etc/default/docker
with DOCKER_OPTS="-H unix:// -H tcp://0.0.0.0:2375"
then sudo service docker restart
. Same connection refused errors.