docker - apt-get 错误:找不到 'docker-ce' 的版本 '5:19.03.4~3-0~ubuntu-bionic'
问题描述
文档
提供了安装特定版本的语法docker-ce
:
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
在类似的行上,下面dockerfile
使用上述语法:
FROM jenkins/jenkins:lts
ENV DEBIAN_FRONTEND=noninteractive
USER root
ARG DOCKER_GID=497
# Create Docker Group with GID
# Set default value of 497 if DOCKER_GID set to blank string by Docker compose
RUN groupadd -g ${DOCKER_GID:-497} docker
# Install base packages for docker, docker-compose & ansible
# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50 && \
RUN apt-get update -y && \
apt-get -y install bc \
gawk \
libffi-dev \
musl-dev \
apt-transport-https \
curl \
python3 \
python3-dev \
python3-setuptools \
gcc \
make \
libssl-dev \
python3-pip
# Used at build time but not runtime
ARG DOCKER_VERSION=5:19.03.4~3-0~ubuntu-bionic
# Install the latest Docker CE binaries and add user `jenkins` to the docker group
RUN apt-get update && \
apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable" && \
apt-get update && \
apt-get -y install docker-ce=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
docker-ce-cli=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
containerd.io && \
usermod -aG docker jenkins
ARG DOCKER_COMPOSE=1.24.1
# Install docker compose
RUN curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE:-1.24.1}/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose
RUN pip3 install ansible boto3
# Change to jenkins user
USER jenkins
# Add jenkins plugin
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
在下面的行失败(构建时):
apt-get -y install docker-ce=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
docker-ce-cli=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
containerd.io && \
从命令中检索默认值的位置:apt-cache madison docker-ce | awk 'NR==1{print $3}'
在我的本地 docker 主机中
其中docker-compose build
给出以下错误:
Reading state information...
E: Version '5:19.03.4~3-0~ubuntu-bionic' for 'docker-ce' was not found
E: Version '5:19.03.4~3-0~ubuntu-bionic' for 'docker-ce-cli' was not found
ERROR: Service 'jenkins' failed to build: The command '/bin/sh -c apt-get update && apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common && curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" && apt-get update && apt-get -y install docker-ce=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} docker-ce-cli=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} containerd.io && usermod -aG docker jenkins' returned a non-zero code: 100
apt-get -y install docker-ce docker-ce-cli containerd.io
可以下载和安装最新版本的ubuntu
包,但是为什么下载和安装特定版本的ubuntu
包失败?
apt-get -y install docker-ce=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
docker-ce-cli=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
containerd.io && \
解决方案
您已根据构建主机上可用的内容选择 Docker 版本,而不是您正在构建的容器映像中可用的内容。jenkins:lts 映像基于 Debian Stretch,而不是 Ubuntu Bionic。
Dockerfiles 实际上只是运行相当普通的 Docker 操作。因此,例如,您可以docker run -ti -u root jenkins/jenkins:lts /bin/bash
手动运行 RUN 脚本,然后检查apt-cache
容器内的输出:
# apt-cache madison docker-ce
docker-ce | 5:19.03.4~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
docker-ce | 5:19.03.3~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
docker-ce | 5:19.03.2~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
docker-ce | 5:19.03.1~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
docker-ce | 5:19.03.0~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
此外,一个失败的 docker 构建应该留下部分完整的图像;因此您可以直接使用它来调查故障。作为一个微不足道的失败步骤的例子RUN false
:
⋮
Removing intermediate container baaeab34bb8c
---> 6d34bab07796
Step 3/3 : RUN false
---> Running in 8347f442dfaa
The command '/bin/sh -c false' returned a non-zero code: 1
6d34bab07796
图像留在周围。您可以将其传递给docker run
并调查命令失败的原因。容器也被8347f442dfaa
留下,虽然已经退出;您也可以使用各种docker container
子命令对其进行调查。
推荐阅读
- routes - 无论如何要在 Appcelerator 中的 MAPS 上删除路线或折线
- ibm-cloud-private - 设置 Helm cli 导致致命的“错误:远程错误:tls:错误证书”
- c - 输出未知输入的十进制版本
- spring-cloud-dataflow - 使用spring cloud skipper在k8s上附加版本作为服务/部署名称背后的合理性
- excel - 如何获取超过截止日期的日期百分比?
- php - 博客文章上的 PHP 时间戳问题
- angular - Angular 单元测试 - 在 ViewChild 中引用/模拟指令
- c# - C# ADO.NET 参数化查询
- python - print 语句执行三次,而执行只执行一次
- python - 在忽略 NaN 的情况下连接 pandas DataFrame 中的列值