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

如何在私有仓库的Node.js UBI9极简镜像中安装shadow-utils?

解决方法

首先看报错Failed to create: /var/cache/yum/metadata,大概率是权限问题或者仓库配置缺失,按以下步骤排查:

1. 优先解决权限问题

很多极简镜像为了安全,默认会切换到非root用户运行,而microdnf install需要写入系统目录,必须以root权限执行。修改Dockerfile,在RUN命令前切换回root:

FROM private.repo.com/node:20.9.0_ubi9

USER root
RUN microdnf install shadow-utils -y && \
    microdnf clean all
# 如果后续需要非root运行,可再切回原用户,比如:
# USER node

2. 检查仓库配置(权限修复后仍报错时)

ubi9极简镜像可能未预装官方仓库配置,或者你的私有仓库未同步shadow-utils所在的ubi官方仓库。可以手动添加ubi基础仓库配置后再安装:

FROM private.repo.com/node:20.9.0_ubi9

USER root
RUN echo -e '[ubi-baseos]\nname=UBI BaseOS Repository\nbaseurl=https://cdn.redhat.com/content/public/ubi/dist/ubi9/9/x86_64/baseos/\ngpgcheck=1\ngpgkey=https://cdn.redhat.com/content/public/ubi/dist/ubi9/9/x86_64/baseos/RPM-GPG-KEY-redhat-release' > /etc/yum.repos.d/ubi-baseos.repo && \
    echo -e '[ubi-appstream]\nname=UBI AppStream Repository\nbaseurl=https://cdn.redhat.com/content/public/ubi/dist/ubi9/9/x86_64/appstream/\ngpgcheck=1\ngpgkey=https://cdn.redhat.com/content/public/ubi/dist/ubi9/9/x86_64/appstream/RPM-GPG-KEY-redhat-release' > /etc/yum.repos.d/ubi-appstream.repo && \
    microdnf install shadow-utils -y && \
    microdnf clean all

注:如果环境无法访问公网,需要将这些仓库同步到你的私有仓库,再把baseurl替换为私有仓库地址。

3. 验证私有仓库是否包含目标包

如果前两步都无效,确认私有仓库是否存在shadow-utils包。可临时进入基础镜像排查:

docker run --rm -it private.repo.com/node:20.9.0_ubi9 /bin/sh
# 切换root后执行
microdnf search shadow-utils

如果搜索不到,说明私有仓库未同步该包,需联系仓库管理员添加。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 10:04:57