WSL: WSL 2.0: `networkingMode=mirrored` makes Docker unable to forward ports

Windows Version

Microsoft Windows [Version 10.0.22631.2338]

WSL Version

2.0.0.0

Are you using WSL 1 or WSL 2?

  • WSL 2

Kernel Version

5.15.123.1-1

Distro Version

Ubuntu 20.04.6

Other Software

Docker version 24.0.6, build ed223bc

Repro Steps

  • Change networkingMode to mirrored
  • docker run -d -p 8080:80 nginx:alpine (example)
  • Go to localhost:8080
  • Cannot connect
  • Try from WSL curl http//localhost:8080 same issue

Expected Behavior

To forward the port and be able to connect to my containers

Actual Behavior

Doesn’t forward the port, so I cannot connect to my containers.

Diagnostic Logs

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 89
  • Comments: 171 (16 by maintainers)

Most upvoted comments

there seem to be two issues why Docker containers cannot connect from Windows.

  1. ignorePorts works Docker Desktop, probably

  2. the port forwarding does work from another machine on the same network as host. Just not on the host machine itself. docker-ce that installed on Linux

temporary measures for 2 … disable iptables and use docker-proxy

/etc/docker/daemon.json

{
    "iptables": false
}

when using mirrored, the behavior seems to be different from the previous localhostforwarding.

use docker-proxy(listen on Linux)

windows  --->  linux(WSL)
  localhostforwarding (until)
ok    127.0.0.1   --->     127.0.0.1(lo)
ok    127.0.0.1   <---     127.0.0.1(lo)

  netowrkingMode=mirrored
ok    127.0.0.1   --->     127.0.0.1(loopback0)
ok    127.0.0.1   <---     127.0.0.1(loopback0)

interface is different, but the behavior remains the same.

use iptables(listeon on container)

windows  --->  linux(WSL) ---> Docker container
  localhostforwarding (until)
ok    127.0.0.1   ---> 127.0.0.1(lo)    /   172.x.x.1(br-xxx)  --->  172.x.x.x(eth0)
ok    127.0.0.1   <--- 127.0.0.1(lo)    /   172.x.x.1(br-xxx)  <---  172.x.x.x(eth0)

  netowrkingMode=mirrored
ok    127.0.0.1   ---> 127.0.0.1(loopback0)/127.0.0.1(br-xxxx) --->  172.x.x.x(eth0)
                                          ~~~~~~~~~
ng                                                           <- - -  172.x.x.x(eth0)

via localhostforwarding(until), source address(Windows) was the docker network gateway (=pointing to linux).

via mirrored, source address is 127.0.0.1. for this reason that packet is returned to 127.0.0.1(localhost on container) and does not reach Windows. in the case of access from another node(PC), there is no problem because source is his address.

Interestingly, the port forwarding does work from another machine on the same network as host. Just not on the host machine itself.

Machine A:

  • Change networkingMode to mirrored
  • docker run -d -p 8080:80 nginx:alpine
  • Go to localhost:8080
  • Cannot connect
  • Set Windows firewall rules to allow 8080 inbound
  • Go to localhost:8080
  • Cannot connect

Machine B:

  • Go to A:8080
  • works

This issue should not be closed, the issue is still there if you’re not using docker desktop. Iptables is more stable then userland proxy

I’m closing this issue out as it’s now fixed! Please upgrade to docker desktop 4.26.0 to get the fix. Thank you all! 😃

So the two workarounds I see so far, both have their negatives but worth listing anyway. Correct any of my misunderstandings.

Option1 - without docker desktop

Edit %USERPROFILE%\.wslconfig file (create it, if doesn’t exist) and add this section

[experimental]
networkingMode=mirrored
hostAddressLoopback=true

Restart WSL, then in your distro, edit /etc/docker/daemon.json and add

{
"iptables": false
}

Then sudo systemctl restart docker.

With this, both normal port usage like python3 -m http.server and docker port usage like docker run -p "8080:8080" --rm -t mendhak/http-https-echo:26 are accessible from Windows side. The disadvantage is that iptables is now disabled.

Option 2 - with Docker Desktop

No longer necessary, update to the latest Docker Desktop and it should start working.

Edit %USERPROFILE%\.wslconfig file (create it, if doesn’t exist) and add this section

[experimental]
networkingMode=mirrored
hostAddressLoopback=true
ignoredPorts = 8000,8080

Restart WSL and ensure Docker Desktop is running. With this, the normal port usage stops working if it uses a port listed above. eg the Python http.server isn’t accessible over 8000 anymore (at least in my testing). Instead use a different port, like python3 -m http.server 8001. Docker ports will work as normal as long as the port is listed in the ignoredPorts above, like docker run -p "8080:8080" --rm -t mendhak/http-https-echo:26

The disadvantage here is you have to know which ports you’ll be using with Docker. And it doesn’t look like ignoredPorts accepts ranges of ports either so it can get pretty tedious.

And ignoredPorts only applies to docker containers it seems, not simple python http servers, unless I messed up? Did anyone run into the ignoredPorts issue as I did, for non-Docker applications?

hello. Docker completed the PR that fixes this issue - https://github.com/moby/moby/pull/48514 This was included in the following Docker release - https://github.com/moby/moby/releases/tag/v27.3.0

Please try Docker version 27.3.0

Same issue here, the only way I found to make it “work” was adding ignoredPorts=8080 to the wslconfig, but if container has something like 4800:8080 need to add both ports to ignoredPorts=8080,4800 still doing this some containers might not work at all, also if cloudflare tunnel is running on WSL this will break to when mirrored and theres no way to know which ports is using to add it to the ignoredPorts

closing since the issue is resolved if you encounter the issue after using Docker version 27.3.0 or later, please open a separate issue

使用ignorePorts 在我的笔记本电脑上不起作用。 我的意思是我仍然无法从 Windows 访问 docker 服务端口。 我只在我的wsl2中安装了docker,并没有在Windows中使用docker桌面客户端。 是这个原因吗?

添加下面配置到wslconfig

[experimental]
autoMemoryReclaim=gradual
networkingMode=mirrored
dnsTunneling=true
firewall=false
autoProxy=false
hostAddressLoopback=true

并且添加 "iptables": false 到 /etc/docker/daemon.json 就好了

Hi folks, we believe we’ve found a fix for this that needs to be added to the Docker engine. We’ve filed a bug for it and are working with the docker team to investigate adding it in: https://github.com/moby/moby/issues/48056

ignorePorts is misleading. What it does is making in this case port 8080 available to request inside the container only, but is not forwarded to Windows side. Look for more details at https://learn.microsoft.com/en-us/windows/wsl/wsl-config

If you run get-nettcpConnection -LocalPort 8080 there’s nothing listening on that port.

After starting the web server with docker run -d -p 8080:80 nginx:alpine requests inside the WSL container works:

zcobol@debian:~$ curl -I localhost:8080
HTTP/1.1 200 OK
Server: nginx/1.25.2
Date: Mon, 25 Sep 2023 16:41:36 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 15 Aug 2023 19:24:07 GMT
Connection: keep-alive
ETag: "64dbd0d7-267"
Accept-Ranges: bytes

Requests from Windows side timeout with:

curl: (28) Failed to connect to localhost port 8080 after 21276 ms: Couldn't connect to server

From another server it work, as mentioned by @driver1998 :

tux@raspi:~$ curl -I 192.168.1.105:8080
HTTP/1.1 200 OK
Server: nginx/1.25.2
Date: Mon, 25 Sep 2023 16:43:45 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 15 Aug 2023 19:24:07 GMT
Connection: keep-alive
ETag: "64dbd0d7-267"
Accept-Ranges: bytes

My favorite flavor of Linux is Ubuntu via Docker via Ubuntu via WSL via Windows 11.

To follow-up on this thread, we are actively working to address this. We are considering solution such as that shown by @shigenobuokamoto earlier in this thread. We are currently considering options and possible side-effects for the multitude of ways Linux might be configured by users.

Thanks everyone for the detailed feedback!

Docker Desktop 4.26.0 Release Notes For Windows * Added support for WSL mirrored mode networking (requires WSL v2.0.4 and up). * Added missing signatures on DLL and VBS files.

+1 for priority. There is a large contingent of corporate devs who need docker and mirrored mode (vpn/sec reqs).

ignoredPorts really isn’t an ideal solution. Hopefully we can get an official update on this item as it’s already quite popular.

@CatalinFetoiu it may not be practical to modify the nft rules set by Docker every time. instead, if you run the following two lines, traffic from the Windows host will be handled by 127.0.0.1 (= docker-proxy).

sudo nft  add chain   'ip nat WSLPREROUTING { type nat hook prerouting priority dstnat - 1; policy accept; }'
sudo nft  insert rule 'ip nat WSLPREROUTING iif loopback0 ip daddr 127.0.0.1 counter dnat to 127.0.0.1'

i have been using this rule for a long time and it does not seem to have any side effects.

Network Mode mirrored does not work for me with docker. Looks like port 2375 is only reachable via IPv6 (netstat - nl | grep 2375 only returns a mapping for ‘tcp6’).

Why I can reach http://localhost:2375/version via Browser, e. g. Testcontainers does not find a docker environment (despite DOCKER_HOST set to ‘tcp://localhost:2375’).

Even after 8 years, docker is just a nightmare with WSL(2).I am literally the only dev using Windows anymore on my team, everyone else is using Macs now where it just works.

@felipecrs

I wonder why iptables: false would not be enough for you.

most issues can be resolved by modifying daemon.json. however, the usability may change by not using iptables. bigger issues is that cannot use docker unless setting daemon.json. my script is just a sample implementation workaround, but if it has a reasonable effect without any negative effects on everyone, i hope that i will be able to propose its inclusion in /init.

https://gist.github.com/shigenobuokamoto/b565d468541fc8be7d7d76a0434496a0

my script is very simple, just apply the following rules to nftables.

table ip nat {
    chain WSLPREROUTING {
        type nat hook prerouting priority dstnat - 1; policy accept;
        iif "loopback0" ip daddr 127.0.0.1 counter dnat to 127.0.0.1;
    }
}

this chain is processed immediately before PREROUTING, and will DNAT destination of the packet that arrives from loopback0 interface to 127.0.0.1 to 127.0.0.1. it may seem like a wasteful process, but adding this action breaks the prerouting hook and disables any Docker rules set in the PREROUTING chain.

using userland-proxy only for access from localhost is the same as Docker’s default behavior.

to: who have already used it i have made some changes from the previous one,

before
  add chain   ip nat PREROUTING { type nat hook prerouting priority dstnat; policy accept; };
  insert rule ip nat PREROUTING iif loopback0 counter accept comment mirrored;

after
  add chain   ip nat WSLPREROUTING { type nat hook prerouting priority dstnat - 1; policy accept; };
  insert rule ip nat WSLPREROUTING iif loopback0  ip daddr 127.0.0.1 counter dnat to 127.0.0.1 comment mirrored;

both are methods to prevent the PREROUTING NAT rule. there is no change in behavior when using with Docker, but i think this is safer because it does not affect the chain managed by iptables.

if you like, please try this as well.

Thank you for posting @AzureZeng

Would appreciate a few more people checking to confirm, but I just did a quick test and it seems to be working better than before, hopefully no other issues appear 🤞

In %USERPROFILE%\.wslconfig I only put this and nothing else:

[experimental]
networkingMode=mirrored

and updated to Docker Desktop 4.26.0

I am now able to

python3 -m http.server

and also

docker run -p 8080:8080 --rm -t mendhak/http-https-echo:31

Both are visible from the Windows side in a browser.

Right: some apps may want to connect to an assigned address instead of loopback. In those cases, it might help those solutions end-to-end to also enable hostAddressLoopback

(hostAddressLoopback is only applicable to Mirrored mode)

@LeorGreenberger i cannot reproduce it. however, there were some parts where the escape was missing, so I fixed it. could you please try this?

https://gist.github.com/shigenobuokamoto/b565d468541fc8be7d7d76a0434496a0

Wow, I couldn’t get it to work in mirrored mode for 4 hours, then it randomly worked after restarting services, killing processes, restarting wsl, running docker desktop as admin etc. The next day I couldn’t open docker desktop, the engine would just not start, for 2 hours.

Modifying my config finally worked:

I added:

firewall=false
dnsTunneling=true

so my config now looks like this:

[wsl2]
networkingMode=mirrored
# localhostForwarding=true
firewall=false
dnsTunneling=true

[experimental]
autoMemoryReclaim=gradual
sparseVhd=true

even if iptables:true, unless you explicitly set userland-proxy: false, access from localhost will go through userlandproxy.

workaround if you don’t want to set iptables:false https://gist.github.com/shigenobuokamoto/b565d468541fc8be7d7d76a0434496a0

i would like microsoft to consider the issues with docker-ce (!= Docker Desktop).

@craigloewen-msft, any words for the people who are not using Docker Desktop (which is not even free)? Is echo '{"iptables": false}' > /etc/docker/daemon.json the proper approach?

Thanks for the work around. We are engaged with the Docker team to have better integration.

I tested with disable iptables for docker in /etc/docker/daemon.json and use docker-proxy instead. It works on my device.

Another thing, when I set autoMemoryReclaim to gradual, all containers won’t start. So I have to set it to dropcache.

My working .wslconfig

[wsl2]
macAddress=02:00:01:02:00:01
memory=8GB

[experimental]
sparseVhd=true
dnsTunneling=true
networkingMode=mirrored
autoMemoryReclaim=dropcache

My /etc/docker/daemon.json content:

{
  "hosts": [
    "tcp://0.0.0.0:2375",
    "unix:///var/run/docker.sock"
  ],
  "iptables": false
}

thanks, but my wsl is older and doesnt set systemd

@zaaack, you can use iptables -t nat -I DOCKER -i loopback0 -d 127.0.0.0/8 -j RETURN¹ or any of the variants² that have been mentioned above.

the issue is that network within WSL behaves differently from normal Linux, so i think it would be best to deal with it on the WSL side.

Also, this would mean that whatever application that relies on the same feature as docker would have the same issue. It could be an old application that doesn’t receive more support for example. Or some application that refuses to implement a fix just for WSL.

So, yeah, I totally agree. The ideal would have been the fix to happen on WSL side.

This issue seems to have been resolved for me with WSL 2.2.4.0. Can anyone else confirm this so we can close the issue?

Thank you @shigenobuokamoto! That did the trick! Since, unfortunately, I do not understand what your script does… I am not able to explain why it works!

Ok, that’s cool, but I hope this issue does not get closed already. What about people who are not using Docker Desktop? (which is not free and neither open source)

Sorry, it was close for internal tracking of issues. If it’s more appropriate, we can keep this open as well.

It works in my test. 😃

@jweaston you can access from Docker container in WSL to Windows host address, WSL 2.3.11 and later.

.wslconfig

[experimental]
hostAddressLoopback=true
Windows host                  WSL Linux                         Docker Container
127.0.0.1    --- loopback --- 127.0.0.1   --- not connected --- 127.0.0.1(same address but unrelated)
192.168.1.10 --- loopback --- 192.168.1.10
                                  | routed
     (unknown network)        172.17.0.1  ----- connected ----- 172.17.0.2

docker container (in WSL) can connect to 192.168.1.10:5966. if you try connect to 127.0.0.1:5966, the packet is sent to container’s 127.0.0.1. so cannot connect to windows host.

When will this fix be built into wsl? Now we can only use service script to make it work, I don’t think this is a long term solution.

Besides, I use nixos-wsl, this is my example module that can be used as a reference for nixos user, from @shigenobuokamoto


{pkgs, ...}: {
    systemd.services.network-mirrored = {
      description = "network-mirrored";
      enable = true;
      wants = ["network-pre.target"];
      wantedBy = ["multi-user.target"];
      before = ["network-pre.target" "shutdown.target"];
      serviceConfig = {
        User = "root";
        ExecStart = [
          ''
            /bin/sh -ec '\
            [ -x /usr/bin/wslinfo ] && [ "$(/usr/bin/wslinfo --networking-mode)" = "mirrored" ] || exit 0;\
            echo "\
            add chain   ip nat WSLPREROUTING { type nat hook prerouting priority dstnat - 1; policy accept; };\
            insert rule ip nat WSLPREROUTING iif loopback0  ip daddr 127.0.0.1 counter dnat to 127.0.0.1 comment mirrored;\
            "|${pkgs.nftables}/bin/nft -f -\
            '
          ''
        ];

        ExecStop = [
          ''
            /bin/sh -ec '\
              [ -x /usr/bin/wslinfo ] && [ "$(/usr/bin/wslinfo --networking-mode)" = "mirrored" ] || exit 0;\
              for chain in "ip nat WSLPREROUTING";\
              do\
                handle=$(${pkgs.nftables}/bin/nft -a list chain $chain | sed -En "s/^.*comment \\"mirrored\\" # handle ([0-9]+)$/\\1/p");\
                for n in $handle; do echo "delete rule $chain handle $n"; done;\
              done|${pkgs.nftables}/bin/nft -f -\
            '
          ''
        ];
        RemainAfterExit = "yes";
      };
    };
}

@codeart1st work on this issue is ongoing in moby (=Docker Engine), so until that is released you can use my script to mitigate the issue. essentially, the issue is that network within WSL behaves differently from normal Linux, so i think it would be best to deal with it on the WSL side.

WSL 2.3.11 includes some improvements to mirrored networking, so i am looking into how to use them to improve the experience. this is the prototype new network-mirrored.service. please try this too.

https://gist.github.com/shigenobuokamoto/540c5f09a03eb07149501e99a6c8d82b

  • taking advantage of the fact that connect from Docker container network to Windows host is now possible, i wrote a more natural nftables.
  • added support for communication between Windows and Linux using 127.0.0.0/8, so i worte the missing route.

@shigenobuokamoto’s solution continues to be rock-solid over many months of 10h/day usage. Write yourself a personal VM setup guide and just copy paste their stuff.

temporary measures for …2 disable iptables and use docker-proxy

/etc/docker/daemon.json

{
    "iptables": false
}

it works for me,but this causes me to not be able to use iptables and I’m still waiting for a real fix. Also, I’ve heard that Docker Desktop 4.26 and later adds support for mirrored network mode.

This is still an issue.

Thank you for posting @AzureZeng

Would appreciate a few more people checking to confirm, but I just did a quick test and it seems to be working better than before, hopefully no other issues appear 🤞

In %USERPROFILE%\.wslconfig I only put this and nothing else:

[experimental]
networkingMode=mirrored

and updated to Docker Desktop 4.26.0

I am now able to

python3 -m http.server

and also

docker run -p 8080:8080 --rm -t mendhak/http-https-echo:31

Both are visible from the Windows side in a browser.

I always find the solution right after it’s been fixed. So lucky.

Ok, that’s cool, but I hope this issue does not get closed already. What about people who are not using Docker Desktop? (which is not free and neither open source)

See above, set networkingMode=mirrored and hostAddressLoopback=true in .wslconfig, then set "iptables": false in /etc/docker/daemon.json.

I think there is not more convenient solution than this, unless Docker team want to improve the experience that running Docker daemon directly in WSL.

this might be closer to the previous behavior. (instead daemon.json)

$ nft insert rule ip nat PREROUTING iif loopback0 counter accept

generally, packets from local loopback are not routed. when mirrored, PREROUTING chain works because it routes packets from loopback0. so let the packets from loopback0 escape from PREROUTING chain.

however, this requires additional configuration. if WSL has set rules for nftables in advance… loopback0.service.gz

@keith-horton Why is this being closed when you are still actively working with Docker? Is there another issue that I can track? Is this workaround an official workaround suggested by MS? 😃 Are there any negative/downsides from turning iptables off in Docker w/ WSL?

Right: some apps may want to connect to an assigned address instead of loopback. In those cases, it might help those solutions end-to-end to also enable hostAddressLoopback

(hostAddressLoopback is only applicable to Mirrored mode)

@keith-horton brother, you just changed my life. thank you

this may seem unnecessary since moby takes care of it, but this is a new improvement plan.

WSL 2.3.11 brings several improvements to communication with Windows host.

therefore, you can now use the following rules to improve communication from Windows host to Docker containers:

$ nft add rule ip nat WSLPOSTROUTING iif "loopback0" ip saddr 127.0.0.0/8 ip daddr != 127.0.0.0/8 counter masquerade
$ sysctl -w net.ipv4.conf.all.route_localnet=1

@felipecrs : right - 2.3.1.1 fixes a variety of Linux container scenarios. This in particular will require Docker to change their route - tracked here: https://github.com/moby/moby/issues/48056.

We are in contact with them and the fix should hopefully be released soon.

@CatalinFetoiu it may not be practical to modify the nft rules set by Docker every time. instead, if you run the following two lines, traffic from the Windows host will be handled by 127.0.0.1 (= docker-proxy).

sudo nft  add chain   'ip nat WSLPREROUTING { type nat hook prerouting priority dstnat - 1; policy accept; }'
sudo nft  insert rule 'ip nat WSLPREROUTING iif loopback0 ip daddr 127.0.0.1 counter dnat to 127.0.0.1'

i have been using this rule for a long time and it does not seem to have any side effects.

seems still have side efforts:

  1. win host --> service in wsl, ok
  2. wsl --> service in win host, ok
  3. win host --> service in wsl docker, ok through localhost/127.0.0.1
  4. wsl docker --> service in win host, no

above bullet 4 in WSL2 NAT workable.

More interestingly… it only works when I have wireshark doing a local loopback capture.

I’m really not feeling like going deeper into win32 the c++ behind npcap… but this is enough c# code to open the loopback device… you dont even have to start a capture just open the device handle and the connection starts working.

// <PackageReference Include="SharpPcap" Version="6.3.0" />
using SharpPcap;

var devices = CaptureDeviceList.Instance;
var targetDevice = @"\Device\NPF_Loopback";
var loopback = devices[targetDevice];
loopback.Open();  // its something behind the wpcap.dll::pcap_activate that is "fixing" my machine.

Console.WriteLine("Fixed!");
Console.ReadLine();

as soon as the process with the above code is ended the machine goes back to not functioning.

hello, thanks for your patience while we investigated this

we are talking with Docker to address this in their product, but in the meantime, you can run these commands to update the Docker nftables rules to allow localhost port forwarding to work

step 1) Run “sudo nft -a list chain ip nat DOCKER”. Example output shown below. table ip nat { chain DOCKER { # handle 4 iifname “docker0” counter packets 0 bytes 0 return # handle 7 iifname != “docker0” meta l4proto tcp tcp dport 8080 counter packets 0 bytes 0 dnat to 172.17.0.2:80 # handle 12 } }

step 2) using the handle of the second rule in the DOCKER chain from step 1 (the rule that includes the “dnat” keyword), run the following command: (please make sure to use the handle from your output in step 1, as the handle number can change)

sudo nft -a delete rule ip nat DOCKER handle 12

step 3) Run the following command. Make sure that the ports and IP address match your output from step 1 (in this case they need to be the same as the rule with handle 12 from step 1)

sudo nft add rule ip nat DOCKER iifname != “docker0” iifname != “loopback0” meta l4proto tcp tcp dport 8080 counter dnat to 172.17.0.2:80

I keep coming back to this and @shigenobuokamoto’s solution is the only thing that works for me.

Waiting for WSL to fix this issue.

Hello,

We’re trying to have a setup of WSL working behind a corporate VPN (Cisco Any Connect).

On Win11/WSL2, so far we have to use networkingMode=mirrored to get WSL to be able to access the Internet. (works fine)

But we’re also trying to use docker inside WSL. Now, with this setup we can’t access our containers that exposes specific ports from our Windows machine. For example portainer on port 9000.

This issue cause us to not be able to use Docker on WSL behind a corporate VPN.

@jsayer101 I don’t understand your configuration. Where is your portainer server deployed, your portainers agents, your firewal/VPN server, the browser you use to access your portainer server (outside your corporate LAN?)… ? Could you draw a picture of it?

If you want to access ports on your WSL from other hosts, does your windows firewall authorize it?

Have you tried the startup script propose above?

Yea something is out of order. Corporate firewall wouldn’t prevent you from accessing WSL on your own computer.

Anyway, add this to your WSL OS (https://github.com/microsoft/WSL/issues/10494#issuecomment-1951848642) and add the following settings to your .wslconfig. It’s similar to what you have but with additional flags. This is working fine across all of my Win11 PCs

[wsl2]
networkingMode=mirrored
firewall=false
dnsTunneling=true

[experimental]
useWindowsDnsCache=true
hostAddressLoopback=true

Still an issue with v4.28.0

Although networkingMode=mirrored is great, I hope it does not get promoted to default without having this issue resolved first. 😅

@shigenobuokamoto Your fix works!!! I ran your service start command as root at the command line. Not tested the stop service yet. Our use case is a windows fat client connected to a backend composed of a bunch of containers started with docker compose in WSL2.

You saved my life!

@shigenobuokamoto This works! I reloaded, stopped and started a bunch of times and I don’t see any escape errors. On stopping the service, I get the following warning, but I am guessing this is expected:

Mar 07 13:57:29 REMLT28981 systemd[1]: Stopping network-mirrored.service...
Mar 07 13:57:29 REMLT28981 sh[221292]: # Warning: table ip nat is managed by iptables-nft, do not touch!
Mar 07 13:57:29 REMLT28981 systemd[1]: network-mirrored.service: Deactivated successfully.
Mar 07 13:57:29 REMLT28981 systemd[1]: Stopped network-mirrored.service.

https://gist.github.com/shigenobuokamoto/b565d468541fc8be7d7d76a0434496a0

how about this?

This worked!!

edit: Spoke too soon. @shigenobuokamoto Seeing this error:

● network-mirrored.service
     Loaded: loaded (/etc/systemd/system/network-mirrored.service; enabled; preset: enabled)
     Active: active (exited) since Wed 2024-03-06 17:58:08 EST; 1min 36s ago
   Main PID: 84 (code=exited, status=0/SUCCESS)

Mar 06 17:58:08 REMLT28981 systemd[1]: Started network-mirrored.service.
Mar 06 17:59:42 REMLT28981 systemd[1]: /etc/systemd/system/network-mirrored.service:19: Ignoring unknown escape>

Works perfectly when I run the script manually in the shell. Think systemd wants something escaped.

Just to update, this issue is still present with WSL 2.1.1.0 and docker 25.0.2.

None of these workaround works. Just change back to NAT and waiting for fix.

Im running docker 24.0.7 with docker desktop version 4.26.1 and i’m still experiencing the issue:

WSL version: 2.0.0.0
Kernel version: 5.15.123.1-1
WSLg version: 1.0.57
MSRDC version: 1.2.4485
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25880.1000-230602-1350.main
Windows version: 10.0.22631.2861

https://github.com/microsoft/WSL/assets/6466560/cb659445-dc55-45a9-ac1a-d9b4388bf8bd

Not sure if i’m doing something wrong but it feels very much not solved 😂 happy to help diagnose 😉

Yes, I’m aware of that and that’s what I am using. BTW, I don’t need to set hostAddressLoopback=true and apparently it still works fine.

But I do expect some answer from either the WSL team or Docker as to if this is the recommended/final approach or not.

Sorry, it was close for internal tracking of issues. If it’s more appropriate, we can keep this open as well.

Does that mean a fix has been developed and we’re just waiting on a new version? If so, awesome! Thank you!

@caaat233 it works indeed, thanks a lot! All it takes is to put {"iptables": false}.