在将非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容器内被拒绝
发布评论