无法创建目录.权限在Docker容器内被拒绝

编程入门 行业动态 更新时间:2024-10-26 10:39:19
本文介绍了无法创建目录.权限在Docker容器内被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在将非root用户添加到sudoers组的映像构建过程中,无法创建文件夹.这是我的Dockerfile:

Can not create folder during image building with non root user added to sudoers group. Here is my Dockerfile:

FROM ubuntu:16.04 RUN apt-get update && \ apt-get -y install sudo RUN adduser --disabled-password --gecos '' newuser \ && adduser newuser sudo \ && echo '%sudo ALL=(ALL:ALL) ALL' >> /etc/sudoers USER newuser RUN mkdir -p /newfolder WORKDIR /newfolder

我收到错误消息:mkdir: cannot create directory '/newfolder': Permission denied

推荐答案

Docker容器内的文件系统就像Docker容器外的文件系统一样工作:如果要创建文件或目录,则需要适当的权限.在这种情况下,您试图以非root用户身份创建/newfolder(因为USER指令更改了用于运行其后所有命令的UID).这是行不通的,因为/由root拥有并且具有模式dr-xr-xr-x.

Filesystems inside a Docker container work just like filesytems outside a Docker container: you need appropriate permissions if you are going to create files or directories. In this case, you're trying to create /newfolder as a non-root user (because the USER directive changes the UID used to run any commands that follow it). That won't work because / is owned by root and has mode dr-xr-xr-x.

请尝试:

RUN mkdir -p /newfolder RUN chown newuser /newfolder USER newuser WORKDIR /newfolder

这会将目录创建为root,然后将其创建为chown.

This will create the directory as root, and then chown it.

更多推荐

无法创建目录.权限在Docker容器内被拒绝

本文发布于:2023-10-23 06:15:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520032.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被拒   权限   容器内   目录   Docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!