buildah 似乎无法处理 `npm install` 写入文件“`/sys/fs/cgroup/cgroup.subtree_control`:不支持操作”

发布于 2025-01-11 05:10:32 字数 3434 浏览 0 评论 0原文

当我尝试使用 buildah 构建容器映像时出现以下错误

[1/2] STEP 7/8: RUN npm install
error running container: error from crun creating container for [/bin/sh -c npm install]: writing file `/sys/fs/cgroup/cgroup.subtree_control`: Operation not supported

环境/步骤

  1. 我已在名为 tools-image 的 ubuntu 容器映像中安装了 buildah
  2. 我在 macOS 上运行此 tools-image 容器
  3. 我使用 docker要运行 tool-image 容器,
  4. 我启动 tools-image 容器,并
docker run -it --privileged --name demo -v "$(pwd)":/localmachine
    "myname/myname:v1" /bin/bash
  1. tools-image buildah 中使用> 构建示例应用程序容器映像
buildah bud -t test:v1 -f Dockerfile .

用于与 buildah bud 命令一起使用的示例应用程序容器映像的 Dockerfile

这是 Dockerfile

##############################
#           BUILD
##############################
FROM docker.io/node:17-alpine as BUILD 
COPY src /usr/src/app/src
COPY public /usr/src/app/public
COPY package.json /usr/src/app/
COPY babel.config.js /usr/src/app/
WORKDIR /usr/src/app/
RUN npm install
RUN npm run build

##############################
#           EXAMPLE
##############################
# https://blog.openshift.com/deploy-vuejs-applications-on-openshift/
FROM docker.io/nginx:1.21.4-alpine

RUN apk update \
    apk upgrade \
    apk add --update coreutils

# Add a user how will have the rights to change the files in code
RUN addgroup -g 1500 nginxusers 
RUN adduser --disabled-password -u 1501 nginxuser nginxusers 

# Configure ngnix server
COPY nginx-os4-webapp.conf /etc/nginx/nginx.conf
WORKDIR /code
COPY --from=BUILD /usr/src/app/dist .

# https://zingzai.medium.com/externalise-and-configure-frontend-environment-variables-on-kubernetes-e8e798285b3e
# Configure web-app for environment variable usage
WORKDIR /
COPY docker_entrypoint.sh .
COPY generate_env-config.sh .
RUN chown nginxuser:nginxusers docker_entrypoint.sh
RUN chown nginxuser:nginxusers generate_env-config.sh
RUN chmod 777 docker_entrypoint.sh generate_env-config.sh
RUN chown -R nginxuser:nginxusers /code
RUN chown -R nginxuser:nginxusers /etc/nginx
RUN chown -R nginxuser:nginxusers /tmp
RUN chmod 777 /code
RUN chmod 777 /tmp
RUN chmod 777 /etc/nginx

USER nginxuser

EXPOSE 8080
CMD ["/bin/sh","docker_entrypoint.sh"]

我执行时出错

[1/2] STEP 1/8: FROM docker.io/node:12-alpine AS BUILD
[1/2] STEP 2/8: COPY src /usr/src/app/src
--> d6601e0d631
[1/2] STEP 3/8: COPY public /usr/src/app/public
--> febd88b92b3
[1/2] STEP 4/8: COPY package.json /usr/src/app/
--> 26675130145
[1/2] STEP 5/8: COPY babel.config.js /usr/src/app/
--> 1006f1e8cf3
[1/2] STEP 6/8: WORKDIR /usr/src/app/
--> af1b28ef62c
[1/2] STEP 7/8: RUN npm install
error running container: error from crun creating container for [/bin/sh -c npm install]: writing file `/sys/fs/cgroup/cgroup.subtree_control`: Operation not supported
: exit status 1
[2/2] STEP 1/22: FROM docker.io/nginx:1.21.4-alpine
Trying to pull docker.io/library/nginx:1.21.4-alpine...
error building at STEP "RUN npm install": error while running runtime: exit status 1

Situation

I get following error when I try to build a container image with buildah.

[1/2] STEP 7/8: RUN npm install
error running container: error from crun creating container for [/bin/sh -c npm install]: writing file `/sys/fs/cgroup/cgroup.subtree_control`: Operation not supported

Environment/steps

  1. I have installed buildah in an ubuntu container image called tools-image
  2. I run this tools-image container on a macOS
  3. I use docker to run the tool-image container
  4. I start the tools-image container with
docker run -it --privileged --name demo -v "$(pwd)":/localmachine
    "myname/myname:v1" /bin/bash
  1. I use inside the tools-image buildah to build an example application container image
buildah bud -t test:v1 -f Dockerfile .

Dockerfile for the example application container image I use with buildah bud command

This is the Dockerfile.

##############################
#           BUILD
##############################
FROM docker.io/node:17-alpine as BUILD 
COPY src /usr/src/app/src
COPY public /usr/src/app/public
COPY package.json /usr/src/app/
COPY babel.config.js /usr/src/app/
WORKDIR /usr/src/app/
RUN npm install
RUN npm run build

##############################
#           EXAMPLE
##############################
# https://blog.openshift.com/deploy-vuejs-applications-on-openshift/
FROM docker.io/nginx:1.21.4-alpine

RUN apk update \
    apk upgrade \
    apk add --update coreutils

# Add a user how will have the rights to change the files in code
RUN addgroup -g 1500 nginxusers 
RUN adduser --disabled-password -u 1501 nginxuser nginxusers 

# Configure ngnix server
COPY nginx-os4-webapp.conf /etc/nginx/nginx.conf
WORKDIR /code
COPY --from=BUILD /usr/src/app/dist .

# https://zingzai.medium.com/externalise-and-configure-frontend-environment-variables-on-kubernetes-e8e798285b3e
# Configure web-app for environment variable usage
WORKDIR /
COPY docker_entrypoint.sh .
COPY generate_env-config.sh .
RUN chown nginxuser:nginxusers docker_entrypoint.sh
RUN chown nginxuser:nginxusers generate_env-config.sh
RUN chmod 777 docker_entrypoint.sh generate_env-config.sh
RUN chown -R nginxuser:nginxusers /code
RUN chown -R nginxuser:nginxusers /etc/nginx
RUN chown -R nginxuser:nginxusers /tmp
RUN chmod 777 /code
RUN chmod 777 /tmp
RUN chmod 777 /etc/nginx

USER nginxuser

EXPOSE 8080
CMD ["/bin/sh","docker_entrypoint.sh"]

Error when I execute

[1/2] STEP 1/8: FROM docker.io/node:12-alpine AS BUILD
[1/2] STEP 2/8: COPY src /usr/src/app/src
--> d6601e0d631
[1/2] STEP 3/8: COPY public /usr/src/app/public
--> febd88b92b3
[1/2] STEP 4/8: COPY package.json /usr/src/app/
--> 26675130145
[1/2] STEP 5/8: COPY babel.config.js /usr/src/app/
--> 1006f1e8cf3
[1/2] STEP 6/8: WORKDIR /usr/src/app/
--> af1b28ef62c
[1/2] STEP 7/8: RUN npm install
error running container: error from crun creating container for [/bin/sh -c npm install]: writing file `/sys/fs/cgroup/cgroup.subtree_control`: Operation not supported
: exit status 1
[2/2] STEP 1/22: FROM docker.io/nginx:1.21.4-alpine
Trying to pull docker.io/library/nginx:1.21.4-alpine...
error building at STEP "RUN npm install": error while running runtime: exit status 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬 2025-01-18 05:10:32

它与 podman 一起工作!

为我解决问题的步骤:

  1. 我在 macOS 上安装了 podman
  2. 我用 podman 构建了 tools-image
  3. 我启动了 tools- image 使用以下命令
podman run -it --rm  --privileged --name demo "tools-image:v1"
  1. 我将示例应用程序的代码克隆到 tools-image 运行容器中
  2. 我使用以下命令运行 buildah
buildah bud -t test:v1 -f Dockerfile .

结果

与 podman 配合使用!

[2/2] COMMIT test:v1
Getting image source signatures
Copying blob 1a058d5342cc [--------------] 0.0b / 0.0b
Copying blob ad93babfd60c [--------------] 0.0b / 0.0b
Copying blob 5af959103b90 [--------------] 0.0b / 0.0b
Copying blob 385374b911f2 [--------------] 0.0b / 0.0b
Copying blob eabae5075c43 [--------------] 0.0b / 0.0b
Copying blob 3d71b657b020 [--------------] 0.0b / 0.0b
Copying blob 57627a47445a done  
Copying config 204e250881 [========] 10.6KiB / 10.6KiB
Writing manifest to image destination
Storing signatures
--> 204e250881d
Successfully tagged localhost/test:v1
204e250881d44984be77c4abfef100880bda165b3d195606880fcad026b57003

It worked with podman!

Steps which solved the problem for me:

  1. I installed podman on macOS
  2. I builded the tools-image with podman
  3. I started the tools-image with following command
podman run -it --rm  --privileged --name demo "tools-image:v1"
  1. I cloned the code for the example application into the tools-image running container
  2. I ran buildah with following command
buildah bud -t test:v1 -f Dockerfile .

Result

It worked with podman!

[2/2] COMMIT test:v1
Getting image source signatures
Copying blob 1a058d5342cc [--------------] 0.0b / 0.0b
Copying blob ad93babfd60c [--------------] 0.0b / 0.0b
Copying blob 5af959103b90 [--------------] 0.0b / 0.0b
Copying blob 385374b911f2 [--------------] 0.0b / 0.0b
Copying blob eabae5075c43 [--------------] 0.0b / 0.0b
Copying blob 3d71b657b020 [--------------] 0.0b / 0.0b
Copying blob 57627a47445a done  
Copying config 204e250881 [========] 10.6KiB / 10.6KiB
Writing manifest to image destination
Storing signatures
--> 204e250881d
Successfully tagged localhost/test:v1
204e250881d44984be77c4abfef100880bda165b3d195606880fcad026b57003
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文