You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建Debian 10.7 Docker镜像时readlink -m选项报错求助

解决BusyBox readlink不支持-m选项导致libc6安装失败问题

问题场景

构建基于Debian 10.7的Docker镜像时,执行到安装指定版本libc6=2.28-10+deb10u2的步骤时,触发BusyBox版本readlink不支持-m选项的错误,即使提前安装了coreutils包也未解决。

原Dockerfile代码

FROM debian:10.7

ARG DEBIAN_FRONTEND=noninteractive

RUN echo "Acquire::http::Proxy \"${HTTP_PROXY}\";" >> /etc/apt/apt.conf.d/50proxy && echo "Acquire::https::Proxy \"${HTTPS_PROXY}\";" >> /etc/apt/apt.conf.d/50proxy

# Install coreutils, dialog, apt-utils since busybox seems to lack them
RUN apt-get update && apt-get install -y coreutils diffutils dialog apt-utils

# Update openssl to the latest version
RUN apt-get update && apt-get upgrade -y openssl

# installing jq and envsubst binary, very useful for shell templating
RUN apt-get update && apt-get install -y --no-install-recommends \
    libc6=2.28-10+deb10u2 \
    && apt-get upgrade -y && apt-get install -y jq bash gettext-base openssl ca-certificates && rm -rf /var/lib/apt/lists/*


RUN ls -alt /usr/local/share/ca-certificates/ \
    && echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
    && ls -alt /etc/ssl/certs/

RUN update-ca-certificates

RUN echo YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY \
    && ls -alt /etc/ssl/certs/

RUN echo "export http_proxy=${HTTP_PROXY}" >> /etc/profile.d/proxy.sh && echo "export https_proxy=${HTTPS_PROXY}" >> /etc/profile.d/proxy.sh && echo "export no_proxy=${NO_PROXY}" >> /etc/profile.d/proxy.sh

# Add Tini
COPY files/tini-amd64-0.17.0 /sbin/tini

# Force the installation of the package maintainer's version of the openssl.cnf file
RUN echo 'openssl openssl/cnf note' | debconf-set-selections && \
    apt-get install -y --no-install-recommends openssl=1.1.1d-0+deb10u7 --reinstall -o Dpkg::Options::="--force-confnew"

错误日志

readlink: unrecognized option: m
BusyBox v1.33.1 () multi-call binary.
Usage: readlink [-fnv] FILE
Display the value of a symlink
    -f  Canonicalize by following all symlinks
    -n  Don't add newline
    -v  Verbose
dpkg: error processing archive /var/cache/apt/archives/libc6_2.28-10+deb10u2_amd64.deb (--unpack):
 new libc6:amd64 package pre-installation script subprocess returned error exit status 1

解决思路

1. 替换BusyBox的readlink为coreutils版本(推荐)

Debian镜像中,BusyBox的readlink位于/bin/readlink,而coreutils安装的readlink位于/usr/bin/readlink,后者支持-m选项。安装coreutils后,直接创建软链接覆盖BusyBox版本:

修改安装coreutils的指令:

# Install coreutils, dialog, apt-utils since busybox seems to lack them
RUN apt-get update && apt-get install -y coreutils diffutils dialog apt-utils \
    && ln -sf /usr/bin/readlink /bin/readlink

这样后续执行libc6的预安装脚本时,会调用支持-m选项的readlink,避免错误。

2. 调整PATH优先级

如果不想覆盖原readlink,可以调整环境变量PATH,让/usr/bin优先于/bin,确保coreutils的readlink被先调用:

在安装coreutils后添加:

RUN echo 'export PATH=/usr/bin:$PATH' >> /etc/profile && source /etc/profile

或者在执行安装libc6的指令前临时设置PATH:

RUN PATH=/usr/bin:$PATH apt-get update && apt-get install -y --no-install-recommends \
    libc6=2.28-10+deb10u2 \
    && apt-get upgrade -y && apt-get install -y jq bash gettext-base openssl ca-certificates && rm -rf /var/lib/apt/lists/*

3. 跳过预安装脚本(不推荐)

使用dpkg选项跳过libc6的预安装脚本,但这种方法可能导致系统依赖或配置异常,仅作为临时应急方案:

RUN apt-get update && apt-get install -y --no-install-recommends libc6=2.28-10+deb10u2 \
    -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" --no-pre-invoke \
    && apt-get upgrade -y && apt-get install -y jq bash gettext-base openssl ca-certificates && rm -rf /var/lib/apt/lists/*

内容的提问来源于stack exchange,提问作者Stefan Neacsu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 20:55:44