You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian Docker镜像apt-get连接被拒但Ubuntu镜像正常的问题

解决Debian Stretch Docker镜像无法联网更新的问题

Hey there! Let's break down why your debian:stretch Docker image is failing to connect to Debian's repositories (and even getting stuck on ping), while Ubuntu images work perfectly. The root cause ties directly to the age of the Stretch release and changes to Debian's repository infrastructure.

核心原因:Debian Stretch已终止官方支持

Debian 9 (Stretch) reached its End of Life (EOL) back in June 2022. This means:

  • The official repositories (deb.debian.org and security.debian.org) no longer host Stretch packages or updates. Any requests to these addresses on port 80 will get connection refused responses, exactly what you're seeing.
  • Ubuntu's Xenial (16.04), while also an older release, still has archived repository support (or your specific Ubuntu image uses a still-functional mirror), which is why apt-get update works there.

快速修复:替换为Debian归档源

Since the original sources are dead, you need to point your Stretch image to Debian's archive servers, which host old EOL releases. Here's how to do it inside the container:

  1. First, back up the original sources list (just in case):
    cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. Overwrite the sources file with the archive repository addresses:
    echo "deb http://archive.debian.org/debian stretch main contrib non-free" > /etc/apt/sources.list
    echo "deb http://archive.debian.org/debian-security stretch/updates main contrib non-free" >> /etc/apt/sources.list
    
  3. Run apt-get update with a flag to bypass expired repository signatures (since archive sources don't get updated signatures anymore):
    apt-get update --allow-insecure-repositories
    

If you need to install packages afterward, you might also need to add --allow-unauthenticated to the apt-get install command, e.g.:

apt-get install --allow-unauthenticated nginx

关于ping google.ca卡住的问题

This is likely a secondary issue related to DNS or network routing in the Stretch container. A quick test is to run the container with a public DNS server specified to rule out DNS problems:

docker run --rm -it --dns 8.8.8.8 debian:stretch

Once you fix the repository sources, you can troubleshoot this further if needed, but the main blocker is the expired repository addresses.

长远建议

Avoid using EOL Debian releases like Stretch in your Docker images. They lack security updates, have broken repository access, and will cause ongoing issues. Instead, use a supported Debian release like Bookworm (12) or Bullseye (11) for stability and security.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:04:57