You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Ubuntu 17.10下Docker容器无法联网:docker0非默认地址启动问题

Fixing Docker Container Internet Access on Ubuntu 17.10 (Custom docker0 Subnet)

Alright, let's tackle this problem head-on. The core issue here is that your organization's internal network is using Docker's default 172.17.0.1 gateway, so you need to reconfigure the docker0 bridge to use a custom subnet—but the default-gateway setting is causing Docker to fail when set to 192.168.220.1. Here's how to resolve this:

  • Diagnose the Current Configuration

    • First, check your existing Docker daemon config and network setup:
      • View your current daemon.json:
        cat /etc/docker/daemon.json
        
      • Check if 192.168.220.1 is already in use by another network interface on your host:
        ip addr show
        
    • Common failure causes include: the gateway IP is already occupied by another NIC (like eth0 or wlan0), or your subnet definition doesn't include the gateway IP.
  • Correctly Configure the Custom Subnet

    • The bip (bridge IP) parameter in daemon.json defines both the docker0 subnet and its gateway in one line, avoiding conflicts with a separate default-gateway setting. Use this valid config:
      {
        "bip": "192.168.220.1/24"
      }
      
    • This sets docker0 to use the 192.168.220.0/24 subnet with 192.168.220.1 as the gateway. If that IP is taken, pick another valid one in the subnet (e.g., 192.168.220.254) and adjust the bip:
      {
        "bip": "192.168.220.254/24"
      }
      
  • Clean Up and Restart Docker

    • Before restarting, remove the old docker0 bridge to avoid conflicts:
      1. Stop the Docker service:
        systemctl stop docker
        
      2. Install bridge utilities if missing:
        apt update && apt install bridge-utils -y
        
      3. Delete the existing docker0 bridge:
        ip link set dev docker0 down && brctl delbr docker0
        
      4. Start Docker back up:
        systemctl start docker
        
  • Verify the Fix

    • Check if docker0 is using your new subnet:
      ip addr show docker0
      
    • Test internet access from a container:
      docker run --rm alpine ping -c 3 google.com
      
    • If the ping succeeds, your containers now have internet access.
  • Troubleshoot Persistent Startup Failures

    • If Docker still won't start, check service logs for specific errors:
      journalctl -u docker.service -f
      
    • Logs will reveal issues like IP conflicts, invalid subnet ranges, or other configuration problems to adjust.

内容的提问来源于stack exchange,提问作者VorpalSword

火山引擎 最新活动