大网数据广告活动
服务器运维问答

Error running mknod within buildah

· 52CE 我爱测

I'm working on converting my existing CentOS 7 Docker image build process to use Buildah and I'm running into an issue with mknod . Currently I use the following Dockerfile to build a new image. So basically building an image wit…

问题原文

原帖链接 · Mark C · CC BY-SA 4.0

I'm working on converting my existing CentOS 7 Docker image build process to use Buildah and I'm running into an issue with mknod.

Currently I use the following Dockerfile to build a new image. So basically building an image with an image in order to avoid dependencies on the build host. I run it like this:

docker build -f Dockerfile.builder -t centosbuilder:latest . && \
docker run --rm centosbuilder:latest | docker import - mycentos:latest

And here's the Dockerfile:

FROM centos:7

ENV ROOTFS /image_build_root
ENV TMPDIR /tmp/image_build

WORKDIR ${TMPDIR}
RUN mkdir -p ${ROOTFS}
RUN mkdir -m 755 ${ROOTFS}/dev && \
    mknod -m 600 ${ROOTFS}/dev/console c 5 1 && \
    mknod -m 600 ${ROOTFS}/dev/initctl p && \
    mknod -m 666 ${ROOTFS}/dev/full c 1 7 && \
    mknod -m 666 ${ROOTFS}/dev/null c 1 3 && \
    mknod -m 666 ${ROOTFS}/dev/ptmx c 5 2 && \
    mknod -m 666 ${ROOTFS}/dev/random c 1 8 && \
    mknod -m 666 ${ROOTFS}/dev/tty c 5 0 && \
    mknod -m 666 ${ROOTFS}/dev/tty0 c 4 0 && \
    mknod -m 666 ${ROOTFS}/dev/urandom c 1 9 && \
    mknod -m 666 ${ROOTFS}/dev/zero c 1 5
RUN yum --installroot=${ROOTFS} --releasever=7 --setopt=tsflags=nodocs --setopt=group_package_types=mandatory -y groupinstall Core
RUN yum --installroot=${ROOTFS} -y clean all
RUN echo "NETWORKING=yes" > ${ROOTFS}/etc/sysconfig/network && \
    echo "HOSTNAME=localhost.localdomain" > ${ROOTFS}/etc/sysconfig/network
RUN rm -rf ${ROOTFS}/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive} && \
    #  docs and man pages
    rm -rf ${ROOTFS}/usr/share/{man,doc,info,gnome/help} && \
    #  cracklib
    rm -rf ${ROOTFS}/usr/share/cracklib && \
    #  i18n
    rm -rf ${ROOTFS}/usr/share/i18n && \
    #  yum cache
    rm -rf ${ROOTFS}/var/cache/yum && \
    mkdir -p --mode=0755 ${ROOTFS}/var/cache/yum && \
    #  sln
    rm -rf ${ROOTFS}/sbin/sln && \
    #  ldconfig
    rm -rf ${ROOTFS}/etc/ld.so.cache ${ROOTFS}/var/cache/ldconfig && \
    mkdir -p --mode=0755 ${ROOTFS}/var/cache/ldconfig
CMD /usr/bin/tar -cf - -C ${ROOTFS} .

Using Buildah, I run into my first error on this line:

$ buildah run "${BUILDER}" mknod -m 600 "${ROOTFS}/dev/console" c 5 1
/usr/bin/mknod: '/image_build_root/dev/console': Operation not permitted
ERRO exit status 1

I've tried running my build script (see below) as root to no avail. I assumed maybe the CAP_MKNOD capability wasn't being set, but I get the same error even if I manually enable it.

Build script:

#!/bin/bash -x

set -e

ROOTFS=/image_build_root
TMPDIR=/tmp/image_build

BUILDER="$(buildah from docker.io/library/centos:7)"
buildah config --workingdir "${TMPDIR}" "${BUILDER}"
buildah run "${BUILDER}" mkdir -p "${ROOTFS}"
buildah run "${BUILDER}" mkdir -m 755 "${ROOTFS}/dev"
buildah run --cap-add=CAP_MKNOD "${BUILDER}" mknod -m 600 "${ROOTFS}/dev/console" c 5 1
buildah run "${BUILDER}" mknod -m 600 "${ROOTFS}/dev/initctl" p
buildah run "${BUILDER}" mknod -m 666 "${ROOTFS}/dev/full" c 1 7
buildah run "${BUILDER}" mknod -m 666 "${ROOTFS}/dev/null" c 1 3
buildah run "${BUILDER}" mknod -m 666 "${ROOTFS}/dev/ptmx" c 5 2
buildah run "${BUILDER}" mknod -m 666 "${ROOTFS}/dev/random" c 1 8
buildah run "${BUILDER}" mknod -m 666 "${ROOTFS}/dev/tty" c 5 0
buildah run "${BUILDER}" mknod -m 666 "${ROOTFS}/dev/tty0" c 4 0
buildah run "${BUILDER}" mknod -m 666 "${ROOTFS}/dev/urandom" c 1 9
buildah run "${BUILDER}" mknod -m 666 "${ROOTFS}/dev/zero" c 1 5
buildah run "${BUILDER}" yum \
    --installroot="${ROOTFS}" \
    --releasever=7 \
    --setopt=tsflags=nodocs \
    --setopt=group_package_types=mandatory \
    -y \
    groupinstall Core
buildah run "${BUILDER}" yum --installroot="${ROOTFS}" -y clean all
buildah run "${BUILDER}" echo "NETWORKING=yes" > "${ROOTFS}/etc/sysconfig/network"
buildah run "${BUILDER}" echo "HOSTNAME=localhost.localdomain" > "${ROOTFS}/etc/sysconfig/network"
buildah run "${BUILDER}" rm -rf \
    "${ROOTFS}/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive}" \
    "${ROOTFS}/usr/share/{man,doc,info,gnome/help}" \
    "${ROOTFS}/usr/share/cracklib" \
    "${ROOTFS}/usr/share/i18n" \
    "${ROOTFS}/var/cache/yum" \
    "${ROOTFS}/sbin/sln" \
    "${ROOTFS}/etc/ld.so.cache" \
    "${ROOTFS}/var/cache/ldconfig"
buildah run "${BUILDER}" mkdir -p --mode=0755 "${ROOTFS}/var/cache/yum"
buildah run "${BUILDER}" mkdir -p --mode=0755 "${ROOTFS}/var/cache/ldconfig"
buildah config --cmd /usr/bin/tar -cf - -C "${ROOTFS}" . "${BUILDER}"
buildah commit "${BUILDER}" centos7builder

已采纳解答

原帖链接 · puchu · CC BY-SA 4.0

An unprivileged user (rootless) has not enough privileges for using mknod, the kernel blocks that. It doesn't matter how many capabilities are left in the user namespace, it won't still be able to use it.

Please refer the following issue.

It is not possible to use mknod and buildah bud/run --isolation="rootless". You need to ignore mknod or use another isolation. It is not possible to mix them. This is awful and nothing can be done.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-03-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。