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源的http
apt-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