#独家
docker 的 ubuntu jammy 如何使用 apt 安装软件?

2023-04-13 0 1,950
FROM ubuntu:jammy
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list
RUN apt update

我要安装软件

要先替换软件源

替换之后需要 apt update

但是貌似不行?

Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Ign:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Err:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
  Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown.  Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/jammy/InRelease  Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown.  Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
W: Some index files failed to download. They have been ignored, or old ones used instead.

改成下面这样也不行

FROM ubuntu:jammy
RUN apt install -y ca-certificates
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list
RUN apt update

也报错

docker build -t "ponponon/redis-cluster" .
[+] Building 0.3s (5/7)                                                                                                                                                         
 => [internal] load .dockerignore                                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                                            0.0s
 => [internal] load build definition from Dockerfile                                                                                                                       0.0s
 => => transferring dockerfile: 234B                                                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/ubuntu:jammy                                                                                                            0.0s
 => CACHED [1/4] FROM docker.io/library/ubuntu:jammy                                                                                                                       0.0s
 => ERROR [2/4] RUN apt install -y ca-certificates                                                                                                                         0.2s
------
 > [2/4] RUN apt install -y ca-certificates:
#0 0.216 
#0 0.216 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
#0 0.216 
#0 0.218 Reading package lists...
#0 0.222 Building dependency tree...
#0 0.222 Reading state information...
#0 0.222 Package ca-certificates is not available, but is referred to by another package.
#0 0.222 This may mean that the package is missing, has been obsoleted, or
#0 0.222 is only available from another source
#0 0.222 
#0 0.222 E: Package 'ca-certificates' has no installation candidate
------
Dockerfile:2
--------------------
   1 |     FROM ubuntu:jammy
   2 | >>> RUN apt install -y ca-certificates
   3 |     RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list
   4 |     RUN apt update
--------------------
ERROR: failed to solve: process "/bin/sh -c apt install -y ca-certificates" did not complete successfully: exit code: 100
make: *** [Makefile:12:docker-build] 错误 1

所以这不久变成了先有鸡还是先有蛋的问题了吗?

我安装软件需要网络,需要使用网络需要 ca-certificate,安装 ca-certificates 需要网络?

要用源才行,docker中的apt是没有安装这个包的,是无法使用https源的httpapt-transport-https

而且你就一个仓库也不对,会有一些包缺失的,按照tuna官方文档,应该配置至少4个源 https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

一个简单的shell脚本自适应ubuntu镜像:

source /etc/os-release
cat > /etc/apt/sources.list <<EOF
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${VERSION_CODENAME} main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${VERSION_CODENAME}-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${VERSION_CODENAME}-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${VERSION_CODENAME}-security main restricted universe multiverse
EOF
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

1. JK下载官网所有资源来源于开发团队,加入会员即可下载使用!如有问题请联系右下角在线客服!
2. JK下载官方保障所有软件都通过人工亲测,为每位会员用户提供安全可靠的应用软件、游戏资源下载及程序开发服务。
3. JK开发团队针对会员诉求,历经多年拥有现今开发成果, 每款应用程序上线前都经过人工测试无误后提供安装使用,只为会员提供安全原创的应用。
4. PC/移动端应用下载后如遇安装使用问题请联系右下角在线客服或提交工单,一对一指导解决疑难。

JK软件下载官网 技术分享 docker 的 ubuntu jammy 如何使用 apt 安装软件? https://www.jkxiazai.com/1524.html

JK软件应用商店是经过官方安全认证,保障正版软件平台

相关资源

官方客服团队

为您解决烦忧 - 24小时在线 专业服务