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.1is already in use by another network interface on your host:ip addr show
- View your current
- Common failure causes include: the gateway IP is already occupied by another NIC (like
eth0orwlan0), or your subnet definition doesn't include the gateway IP.
- First, check your existing Docker daemon config and network setup:
Correctly Configure the Custom Subnet
- The
bip(bridge IP) parameter indaemon.jsondefines both thedocker0subnet and its gateway in one line, avoiding conflicts with a separatedefault-gatewaysetting. Use this valid config:{ "bip": "192.168.220.1/24" } - This sets
docker0to use the192.168.220.0/24subnet with192.168.220.1as the gateway. If that IP is taken, pick another valid one in the subnet (e.g.,192.168.220.254) and adjust thebip:{ "bip": "192.168.220.254/24" }
- The
Clean Up and Restart Docker
- Before restarting, remove the old
docker0bridge to avoid conflicts:- Stop the Docker service:
systemctl stop docker - Install bridge utilities if missing:
apt update && apt install bridge-utils -y - Delete the existing
docker0bridge:ip link set dev docker0 down && brctl delbr docker0 - Start Docker back up:
systemctl start docker
- Stop the Docker service:
- Before restarting, remove the old
Verify the Fix
- Check if
docker0is 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.
- Check if
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.
- If Docker still won't start, check service logs for specific errors:
内容的提问来源于stack exchange,提问作者VorpalSword




