解决Docker容器apt无法下载问题

前言

Docker 是一个开源软件,也是一个开放平台,用于开发应用、交付(shipping)应用、运行应用。 Docker允许用户将基础设施(Infrastructure)中的应用单独分割出来,形成更小的颗粒(容器),从而提高交付软件的速度。

在这里插入图片描述

本文内容简要介绍如何解决Docker容器的apt无法下载问题。

实现

问题

当在容器中使用apt下载时(例如apt-get install -y freeglut3-dev),会报如下错误:

Connection failed [IP: x.x.x.x x]
Fetched 935 kB in 7s (131 kB/s)                                                                                                                                                          
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/universe/f/freeglut/freeglut3_2.8.1-3_amd64.deb  Connection failed [IP: x.x.x.x x]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/universe/f/freeglut/freeglut3-dev_2.8.1-3_amd64.deb  Connection failed [IP: x.x.x.x x]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

一般是网络无法连接访问对应包导致的,即使apt-get update也仍然报错。

解决

考虑添加不同的apt源来解决这个问题:

cp /etc/apt/sources.list /etc/apt/sources.list.bak

在sources.list文件头添加其他源:

vi /etc/apt/sources.list
# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# 阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

更新源:

apt-get update -y

如果报错Couldn't create temporary file /tmp/apt*** for passing config to apt-key则说明文件夹权限不足,修改权限:

chmod 777 /tmp

重新更新并验证:

apt-get update -y
apt-get install -y freeglut3-dev

版权说明

本文为原创文章,独家发布在blog.csdn.net/TracelessLe。未经个人允许不得转载。如需帮助请email至[email protected]或扫描个人介绍栏二维码咨询。
在这里插入图片描述

参考资料

[1] Docker - 维基百科,自由的百科全书
[2] 【Ubuntu】Ubuntu 18.04 LTS 更换国内源——解决终端下载速度慢的问题 - 知乎
[3] GPG 错误 tmp目录权限问题_mixboot的博客-CSDN博客
[4] linux - apt-get update not working: Signing/ Verification errors - Super User

你可能感兴趣的:(#,操作系统,docker,linux,bash)