Search code examples
dockerubuntuwindows-10

Installing Docker in Ubuntu on Windows 10 : Failed to Setup IP tables: Unable to enable NAT rule


I am trying to install Docker in Ubuntu on Windows 10 using script below but then I try to run Docker as service service docker start the Docker does not starts and I find an error in docker.log. I was using the same installation instruction on plain Ubuntu machine and had no problem running docker.

failed to start daemon: Error initializing network controller: Error creating default "bridge" network: Failed to Setup IP tables: Unable to enable NAT rule:  (iptables failed: iptables --wait -t nat -I POSTROUTING -s 172.18.0.0/16 ! -o docker0 -j MASQUERADE: iptables: Invalid argument. Run `dmesg' for more information.
 (exit status 1))  

Installation script

# Update the apt package list.
sudo apt-get update -y

# Install Docker's package dependencies.
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

# Download and add Docker's official public PGP key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify the fingerprint.
sudo apt-key fingerprint 0EBFCD88

# Add the `stable` channel's Docker upstream repository.
#
# If you want to live on the edge, you can change "stable" below to "test" or
# "nightly". I highly recommend sticking with stable!
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# Update the apt package list (for the new apt repo).
sudo apt-get update -y

# Install the latest version of Docker CE.
sudo apt-get install -y docker-ce

# Allow your user to access the Docker CLI without needing root access.
sudo usermod -aG docker $USER

Solution

  • I encountered the same problem and here is what I found out. It currently isn't possible to run docker in WSL. The work around is

    • Update the apt package with: sudo apt-get update

    • Install packages to allow apt to use a repository over HTTPS with: sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

    • Add docker's GPG key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    • Set up a stable repository with: sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

    • Update the apt package again: sudo apt-get update

    • Install docker DCE: sudo apt-get install docker-ce

    • Then add this command which notifies docker of the host to communicate: echo "export DOCKER_HOST=localhost:2375" >> ~/.bash_profile

    • Restart your vscode

    • Install docker desktop and go to your settings and check the "Expose daemon tcp://localhost:2375 without TLS".

    With this, I was able to run docker in WSL(ubuntu). Hope it helps.

    credit: https://medium.com/@sebagomez/installing-the-docker-client-on-ubuntus-windows-subsystem-for-linux-612b392a44c4