docker - 在 Windows 10 上的 Ubuntu 中安装 Docker : Failed to Setup IP tables: Unable to enable NAT rule

标签 docker ubuntu windows-10

我正在尝试使用以下脚本在 Windows 10 上的 Ubuntu 中安装 Docker,但随后我尝试将 Docker 作为服务运行 service docker start Docker 没有启动,我在 docker.log 中发现错误。我在普通的 Ubuntu 机器上使用相同的安装说明,运行 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))  

安装脚本
# 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

最佳答案

我遇到了同样的问题,这就是我发现的。
目前无法在 WSL 中运行 docker。解决方法是

  • 使用以下命令更新 apt 包:sudo apt-get update
  • 安装软件包以允许 apt 通过 HTTPS 使用存储库:sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
  • 添加 docker 的 GPG key :curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • 设置一个稳定的存储库:sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • 再次更新apt包:sudo apt-get update
  • 安装 docker DCE:sudo apt-get install docker-ce
  • 然后添加此命令,通知 docker 主机进行通信:echo "export DOCKER_HOST=localhost:2375" >> ~/.bash_profile
  • 重启你的 vscode
  • 安装 docker desktop 并转到您的设置并检查“Expose daemon tcp://localhost:2375 without TLS”。

  • 有了这个,我就可以在 WSL(ubuntu) 中运行 docker。希望能帮助到你。
    信用:https://medium.com/@sebagomez/installing-the-docker-client-on-ubuntus-windows-subsystem-for-linux-612b392a44c4

    关于docker - 在 Windows 10 上的 Ubuntu 中安装 Docker : Failed to Setup IP tables: Unable to enable NAT rule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61140111/

    相关文章:

    git - 是否有使 Robohelp 2019 与 Windows 10 ssh-agent 一起使用的解决方法?

    c++ - C++/WinRT 中的 UWP 可选包

    docker - cp-kafka-connect 是开源组件还是专有组件?

    php - 仅记录 Docker 容器中来自 PHP-FPM 的真正 fatal error

    ruby-on-rails - 在 Ubuntu 上构建 Rails 应用程序时寻找 SVN 最佳实践

    c - 将字符串返回到需要在屏幕上打印的 C 程序形式的 Bash 脚本

    c# - 获取所有 Windows 8/10 toast 通知

    docker - 推送 docker 镜像时连接被拒绝

    docker - 如何访问 docker-for-desktop 上的 PersistentVolume 文件?

    java - "Class.forName("org.mariadb.jdbc.Driver ");"无法工作