How to give folder permissions inside a docker container Folder

后端 未结 2 1846
我寻月下人不归
我寻月下人不归 2020-12-16 09:37

I am creating a folder inside my Dockerfile and I want to give it a write permission. But I am getting permission denied error when I try to do it

FROM pytho         


        
相关标签:
2条回答
  • 2020-12-16 10:16

    I guess you are switching to user "admin" which doesn't have the ownership to change permissions on /app directory. Change the ownership using "root" user. Below Dockerfile worked for me -

    FROM python:2.7
    RUN pip install Flask==0.11.1 
    RUN useradd -ms /bin/bash admin
    COPY app /app
    WORKDIR /app
    RUN chown -R admin:admin /app
    RUN chmod 755 /app
    USER admin
    CMD ["python", "app.py"] 
    

    PS - Try to get rid of "777" permission. I momentarily tried to do it in above Dockerfile.

    0 讨论(0)
  • 2020-12-16 10:25

    As the Other user already pointed out, move USER admin to a later step

    FROM python:2.7
    RUN pip install Flask==0.11.1 
    RUN useradd -ms /bin/bash admin
    COPY --chown=admin:admin app /app
    WORKDIR /app
    USER admin
    CMD ["python", "app.py"] 
    

    For versions release v17.09.0-ce and newer you can use the optional flag --chown=<user>:<group> with either the ADD or COPY commands.

    For example

    COPY --chown=<user>:<group> <hostPath> <containerPath>
    

    The documentation for the --chown flag is documented on Dockerfile Reference page.

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