在Alpine Docker镜像中安装openssh包遇依赖冲突求助
问题描述
我的Dockerfile内容如下:
FROM alpine:latest RUN apk update RUN apk add --no-cache curl openssh sshpass rsync #etc
docker-compose.yml文件内容:
[...] services: my-container: build: context: ./my-folder dockerfile: Dockerfile container_name: my-container restart: unless-stopped #etc
执行命令:
docker-compose up -d --remove-orphans --build
构建时出现错误:
=> ERROR [3/7] RUN apk add --no-cache curl openssh sshpass rsync 3.7s ------ > [3/7] RUN apk add --no-cache curl openssh sshpass rsync: #0 1.448 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/aarch64/APKINDEX.tar.gz #0 1.859 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/aarch64/APKINDEX.tar.gz #0 2.732 ERROR: unable to select packages: #0 2.741 openssh-client-common-9.3_p1-r3: #0 2.741 breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0]
已尝试的操作:更换多个Alpine镜像版本、执行docker builder prune清理缓存、指定openssh具体版本、仅安装openssh,错误依然存在。
补充信息:Docker运行在已完全更新的64位树莓派系统上,Docker版本信息:
$ docker version Client: Docker Engine - Community Version: 24.0.4 API version: 1.43 Go version: go1.20.5 Git commit: 3713ee1 Built: Fri Jul 7 14:50:52 2023 OS/Arch: linux/arm64 Context: default Server: Docker Engine - Community Engine: Version: 24.0.4 API version: 1.43 (minimum version 1.12) Go version: go1.20.5 Git commit: 4ffc614 Built: Fri Jul 7 14:50:52 2023 OS/Arch: linux/arm64 Experimental: false containerd: Version: 1.6.21 GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8 runc: Version: 1.1.7 GitCommit: v1.1.7-0-g860f061 docker-init: Version: 0.19.0 GitCommit: de40ad0
解决思路
- 强制刷新APK索引并清理本地缓存:在
apk update后加入apk cache clean,确保拉取最新的包索引,避免旧缓存引发版本冲突。修改Dockerfile命令:RUN apk update && apk cache clean && apk add --no-cache curl openssh sshpass rsync - 指定兼容的openssh版本组合:直接指定与
openssh-client-common匹配的版本,比如安装同版本的客户端和服务端:RUN apk add --no-cache curl openssh-client=9.3_p1-r3 openssh-server=9.3_p1-r3 sshpass rsync - 切换Alpine镜像源:部分官方源可能存在同步延迟,换成同步及时的源。在
apk update前添加源替换命令:RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN apk update && apk add --no-cache curl openssh sshpass rsync - 彻底清理Docker构建环境:除了
docker builder prune,删除相关镜像和容器后重新构建:docker-compose down -v docker rmi my-container docker builder prune -a docker-compose up -d --build - 改用Alpine稳定分支:
latest标签可能指向刚更新的分支,存在依赖冲突,改用明确的稳定版本,比如alpine:3.17:FROM alpine:3.17 RUN apk update && apk add --no-cache curl openssh sshpass rsync
内容的提问来源于stack exchange,提问作者Alex
相关产品推荐
相关产品推荐

