Docker运行hello-world超时报错求助:Pop!_OS 19.04环境下无法拉取镜像
Hey there! Let's work through this Docker connection issue you're facing—since you're just starting out with Django and Docker, I know this roadblock can feel pretty frustrating. Let's go through practical steps to get that hello-world image running smoothly.
1. Check Network & DNS Settings
The error points to a timeout connecting to Docker Hub, so first let's rule out DNS-related issues:
- Test if you can reach Docker Hub's registry with this command:
If this fails (no response), your system's DNS is probably misconfigured.ping registry-1.docker.io - Update your DNS to use public, reliable servers like Google's or Cloudflare's:
- For systems using
systemd-resolved(common in Pop!_OS), edit/etc/systemd/resolved.confand set:DNS=8.8.8.8 1.1.1.1 - Save the file, then restart the service to apply changes:
sudo systemctl restart systemd-resolved - Alternatively, temporarily edit
/etc/resolv.confto addnameserver 8.8.8.8(note: this change might be overwritten on reboot, so the systemd-resolved method is more permanent).
- For systems using
2. Use Domestic Docker Registry Mirrors
Accessing Docker Hub directly from some regions can be slow or unreliable. Configuring domestic mirrors will speed up image pulls significantly:
- Create or edit the Docker daemon config file:
sudo nano /etc/docker/daemon.json - Paste this content (using popular, stable Chinese mirrors):
{ "registry-mirrors": [ "https://hub-mirror.c.163.com", "https://mirror.baidubce.com" ] } - Save the file, then reload and restart Docker to apply the mirror settings:
sudo systemctl daemon-reload sudo systemctl restart docker - Now try running the hello-world command again:
sudo docker run hello-world
3. Check Proxy & Firewall Settings
If you're behind a proxy or firewall, Docker might not be using the correct network configuration:
- Proxy Configuration:
- Create a proxy config file for Docker:
sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf - Replace
your-proxy-address:portwith your actual proxy details, then paste:[Service] Environment="HTTP_PROXY=http://your-proxy-address:port/" Environment="HTTPS_PROXY=http://your-proxy-address:port/" Environment="NO_PROXY=localhost,127.0.0.1" - Reload and restart Docker to apply the proxy settings:
sudo systemctl daemon-reload sudo systemctl restart docker
- Create a proxy config file for Docker:
- Firewall Check:
- Temporarily disable your firewall (like ufw) to test if it's blocking connections:
sudo ufw disable - If the hello-world command works after this, re-enable the firewall and add a rule to allow Docker traffic:
sudo ufw enable sudo ufw allow docker
- Temporarily disable your firewall (like ufw) to test if it's blocking connections:
4. Verify Docker Version Compatibility
Pop!_OS 19.04 (based on Ubuntu 19.04, codenamed disco) is an older release, and newer Docker versions might have compatibility issues. Try installing a Docker version confirmed to work with this release:
- Uninstall your current Docker installation completely:
sudo apt-get purge docker-ce docker-ce-cli containerd.io sudo rm -rf /var/lib/docker - Install a compatible version (19.03.x is known to work well with Ubuntu 19.04):
sudo apt-get install docker-ce=5:19.03.15~3-0~ubuntu-disco docker-ce-cli=5:19.03.15~3-0~ubuntu-disco containerd.io - Start Docker and test the hello-world command again:
sudo systemctl start docker sudo docker run hello-world
Give these steps a try one by one—most of the time, the DNS or mirror source fix resolves this issue quickly. Once you get that hello-world container running, you'll be all set to start working on your Django project with Docker!
内容的提问来源于stack exchange,提问作者Bobkatabo

