WSL: Rootless `docker` install failed: `ip_tables` not found in module dir

Windows Build Number

Microsoft Windows [Version 10.0.22000.194]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.10.55

Distro Version

Arch Linux (https://github.com/yuk7/ArchWSL)

Other Software

docker 1:20.10.8-1 (no Docker Desktop)

Repro Steps

Expected Behavior

Rootless docker install successfully.

Actual Behavior

> dockerd-rootless-setuptool.sh install
[ERROR] Missing system requirements. Run the following commands to
[ERROR] install the requirements and run this tool again.
[ERROR] Alternatively iptables checks can be disabled with --skip-iptables .

########## BEGIN ##########
sudo sh -eux <<EOF
# Load ip_tables module
modprobe ip_tables
EOF
########## END ##########

Diagnostic Logs

> modprobe ip_tables
modprobe: FATAL: Module ip_tables not found in directory /lib/modules/5.10.55-xanmod1-microsoft-standard-WSL2

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 13
  • Comments: 20

Most upvoted comments

My steps:

  1. Edit (or create) /etc/wsl.conf The following configuration do:
  • enable systemd
  • disable automatic /etc/resolv.conf generation
[boot]
systemd=true

[network]
generateResolvConf=false
  1. Log out and Shut down wsl
  • Run logout
  • Run wsl shutdown
  1. Login again
  • Run ubuntu
  1. Setup rootless
  • Run sudo systemctl disable --now docker.service docker.socket
  • Run dockerd-rootless-setuptool.sh install --skip-iptables
  • Run sudo nano /etc/resolv.conf then add nameserver 1.1.1.1 and save
  1. Test
  • Run logout
  • Run wsl shutdown
  • Run docker run hello-world

Total and Complete Solution

Finally! I’ve figured out the way to install rootless Docker with network working both when pull images and inside containers!

The Solution

  1. Change iptables to iptables-nft or iptables-legacy
    sudo update-alternatives --set iptables /usr/sbin/iptables-nft
    sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-nft
    
  2. Install rootless Docker normally
  3. Write a script to enter Docker’s namespace and setup namespace as same as host’s. Save this to ~/.local/bin/docker-network-setup.sh
    #!/bin/bash
    
    # Step 1: View network settings of host's
    NAMESERVER=$(grep "nameserver" /etc/resolv.conf)
    
    # Step 2: Enter rootless Docker's namespace
    nsenter -U --preserve-credentials -n -m -t $(cat $XDG_RUNTIME_DIR/docker.pid) << EOF
    
    # Step 3: Fix nameserver
    echo "$NAMESERVER" >> /etc/resolv.conf
    
    # Step 4: exit rootless Docker's namespace
    EOF
    
    echo "Docker network setup completed."
    
  4. Setup systemd service Save this to ~/.config/systemd/user/docker-network-setup.service👇🏻
    [Unit]
    Description=Set up Docker network configuration
    After=docker.service
    Wants=docker.service
    
    [Service]
    Type=oneshot
    ExecStart=/bin/bash -c "sleep 1 && $HOME/.local/bin/docker-network-setup.sh"
    RemainAfterExit=true
    
    [Install]
    WantedBy=default.target
    
  5. Setup systemd
    systemctl --user daemon-reload
    systemctl --user enable docker-network-setup.service
    

Source For This Solution

This solution comes from another user’s iptables findings and my own findings. The core idea is change iptables to a usable one and match nameserver settings of docker’s and host’s.

Same issues, using Ubuntu 22.04 in WSL2 (Windows 10)

Is there a workaround to this?

Edit: I have added a user to docker group to bypass this issue, but it’s not the most secure one. Waiting for a real fix

Hello @timsu92 thank you for this solution but I want to know if this works with docker desktop as well.

@shield02 I’m not aware of any way to install rootless Docker Desktop🤔 Currently, I’m using rootless Docker Engine + Portainer. Some information are even more detailed than Docker Desktop!

Hi @phamnhuvu-dev ! However, installing rootless Docker by installing Docker Engine and then make it rootless is just the procedure produces this issue. Due to the missing iptables module, and consequently installing Docker Engine without it, some easy jobs like apt update can’t even execute. Personally, I’m using Docker Desktop as a workaround. But it’s rootful, so I really hope a rootless Docker on WSL coming soon.

@timsu92 @shield02 Thank you guys, I re-checked the document, so if you want to set up docker rootless, there is only Install Docker Engine on Ubuntu way can help. Docker Desktop is not rootless, but there are awesome features that Docker Destop supports you to set up a development environment, but don’t use it to expose a service to the internet to avoid security problems.

But this installs Docker Desktop, which is a “rootful” Docker, not “rootless” Docker

EDIT: the original comment I was replying to is deleted

Seems that docker got the wrong DNS server address from WSL.

I’m using Ubuntu 22.04 on WSL2, and I see this in my /etc/resolv.conf:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.176.1

Using the method described in Docker docs, I entered rootless Docker’s network namespace. From there, I see what Docker daemon sees when accessing the network by opening /etc/resolv.conf:

nameserver 10.0.2.3

Oops! They aren’t the same!


A temporary fix for fetching images

This is a method that’s working only in current boot time. This procedure must be done overagain once rebooted. This solves Docker daemon’s network, but not container’s network.

I’m using rootless Docker installed by dockerd-rootless-setuptool.sh install --skip-iptables since it can’t find iptables module as well.

  1. See what’s the config on the WSL host
    view /etc/resolv.conf
    
  2. Enter Docker’s namespace
    nsenter -U --preserve-credentials -n -m -t $(cat $XDG_RUNTIME_DIR/docker.pid)
    
  3. Modify docker’s DNS to be the same with host’s Paste at least the nameserver line into the config. No privileged editor required.
  4. Come back to your WSL
    exit
    
  5. Run Docker normally. For example:
    docker run --rm hello-world
    

With steps described in https://github.com/microsoft/WSL/issues/7466#issuecomment-1488731997 the docker run hello-world command works for me.

However, DNS does not work for me inside of a container. For example, if I run docker run -it ubuntu bash, then apt-get update in the container, I get an error Temporary failure resolving 'security.ubuntu.com'. These commands work normally when not running Docker in rootless mode.

@phamnhuvu-dev , does DNS/networking work for you inside of a container?

Same issue using Debian 11 inside WSL2, using dockerd-rootless-setuptool.sh install --skip-iptables resulted in no error, but still couldn’t run docker without using sudo…