Cannot create directory. Permission denied inside docker container

后端 未结 1 1244
醉话见心
醉话见心 2020-12-28 12:59

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 &&         


        
相关标签:
1条回答
  • 2020-12-28 13:20

    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.

    Try instead:

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

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

    0 讨论(0)
提交回复
热议问题