Unable to connect to Docker Daemon from Jenkins Docker Plugin on Win10

Hi there,

I have a trouble with connecting to Docker Daemon from Jenkins Docker container: Connection refused: /127.0.0.1:2375

Summary

java.net.ConnectException: Connection refused
Caused: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /127.0.0.1:2375
at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:777)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:636)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:583)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:500)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:462)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:829)

Environment:
Windows 10 Pro
Version: 21H1
OS build: 19043.1110

WSL2
Ubuntu 20.04

Docker for Windows
Docker Engine - Community 20.10.7

Jenkins
Is running in Docker Container
Jenkins 2.289.2
Docker plugin

Run container.

docker run --name jenkins-docker --rm --detach ^   --network jenkins --network-alias docker --env DOCKER_HOST=tcp://docker:2376 ^   --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 ^   --volume jenkins-data:/var/jenkins_home ^ --volume jenkins-docker-certs:/certs/client:ro ^   --publish 8080:8080 --publish 50000:50000 jenkins_blueocean:1.1

Daemon is exposed

Port is listened
image

Error

I read a lot of topics and spend several hours in Google but cannot find the solution.
What am I doing wrong?

The solution is describet here: Networking features in Docker Desktop for Windows | Docker Documentation

I want to connect from a container to a service on the host

The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name host.docker.internal which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Windows.

You can also reach the gateway using gateway.docker.internal .