侧边栏壁纸
  • 累计撰写 16 篇文章
  • 累计创建 52 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

node:alpine 镜像安装 python2 报错 unable to select packages

Stone
2022-09-21 / 0 评论 / 0 点赞 / 568 阅读 / 565 字

前言

最开始使用的是 node:12.22.12-stretch 版本,最终打包完的镜像体积比较大,决定改用 Alpine 基础版镜像来优化体积,直接换成了同版本号前缀的 node:12.22.12-alpine 版本,下面贴一下 Dockerfile 文件几行重点,其余部分已省略。

FROM node:12.22.12-alpine

... ...

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

RUN apk add --update --no-cache wget python make g++ 

... ...

问题描述

当构建镜像进行到 16 步的时候,有报错信息: ERROR: unable to select packages: python (no such package): required by: world[python]

... ...

Step 16/18 : RUN apk add --update --no-cache wget python make g++ 
 ---> Running in 48a9fe605b01
fetch https://mirrors.aliyun.com/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://mirrors.aliyun.com/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  python (no such package):
    required by: world[python]
The command '/bin/sh -c apk add --update --no-cache wget python make g++ 

不知道为什么,挨个排除问题吧!当直接使用容器运行,不构建镜像、不使用阿里镜像源,同样也是失败

[root@localhost ~]# docker run -it --rm node:12.22.12-alpine sh
/ # cat /etc/apk/repositories 
https://dl-cdn.alpinelinux.org/alpine/v3.15/main
https://dl-cdn.alpinelinux.org/alpine/v3.15/community
/ # apk add --update --no-cache python make g++
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  python (no such package):
    required by: world[python]
/ # exit

解决方案

算是两种方案吧,但我感觉还是用方案二靠谱一些

方案一:降级

当我尝试降级使用 node:12.16.1-alpine,竟然成功了

[root@localhost ~]# docker run -it --rm node:12.16.1-alpine sh
/ # apk add --update --no-cache python make g++
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/23) Upgrading musl (1.1.24-r2 -> 1.1.24-r3)
(2/23) Upgrading libstdc++ (9.2.0-r4 -> 9.3.0-r0)
... ...

方案二:指定版本

去 GitHub 中 Node.js 官方 Docker 镜像中查找到 Node:12-alpine image is not working for python #1605,回复中指出 You must have an old cached image, python2 is in the current image definition,改一下版本号就可以解决问题,nice~

apk add --update --no-cache python2 make g++
0

评论区