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

Ubuntu 22.04容器安装MongoDB遇repo.mongodb.org连接超时问题

Ubuntu 22.04容器中MongoDB官方源连接超时问题排查与解决

在Ubuntu 22.04容器中尝试安装MongoDB,先后遵循MongoDB官方教程及Stack Overflow相关步骤,始终无法连接repo.mongodb.org,执行apt update时出现连接超时错误,具体操作及报错如下:

root@62388d67ab12:/# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse
root@62388d67ab12:/# sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:5 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 InRelease
Ign:5 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 InRelease
Ign:5 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 InRelease
Err:5 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 InRelease
  Could not connect to repo.mongodb.org:443 (18.155.173.118), connection timed out Could not connect to repo.mongodb.org:443 (18.155.173.11), connection timed out Could not connect to repo.mongodb.org:443 (18.155.173.63), connection timed out Could not connect to repo.mongodb.org:443 (18.155.173.96), connection timed out
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Failed to fetch https://repo.mongodb.org/apt/ubuntu/dists/focal/mongodb-org/5.0/InRelease  Could not connect to repo.mongodb.org:443 (18.155.173.118), connection timed out Could not connect to repo.mongodb.org:443 (18.155.173.11), connection timed out Could not connect to repo.mongodb.org:443 (18.155.173.63), connection timed out Could not connect to repo.mongodb.org:443 (18.155.173.96), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.

解决步骤

1. 验证容器网络连通性

  • 测试基础公网访问:ping archive.ubuntu.com,确认容器能正常连接外部网络
  • 测试MongoDB源端口:curl -v https://repo.mongodb.org,检查是否能建立HTTPS连接

2. 替换为国内镜像源

若为地域网络限制导致,替换成国内镜像源:

  • 删除原有源文件:rm /etc/apt/sources.list.d/mongodb-org-5.0.list
  • 添加阿里云MongoDB镜像源:
echo "deb [ arch=amd64,arm64 ] https://mirrors.aliyun.com/mongodb/apt/ubuntu focal/mongodb-org/5.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list
  • 更新源:apt update

3. 匹配系统版本的源配置

Ubuntu 22.04代号为jammy,当前使用的是focal(Ubuntu20.04)的源,可尝试替换为对应版本的官方源:

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/5.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list

注:MongoDB 5.0对Ubuntu22.04的支持有限,若仍有问题,建议升级到MongoDB 6.0及以上版本,官方对jammy的适配更完善

4. 重置容器网络

  • 检查容器是否配置了错误的代理,若有需修正HTTPS代理参数
  • 重启容器重置网络栈:docker restart <容器ID>
  • 确认宿主机防火墙未拦截443端口

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 15:06:29