如何在Docker容器内授予文件夹权限 [英] How to give folder permissions inside a docker container Folder

查看:5131
本文介绍了如何在Docker容器内授予文件夹权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Dockerfile内创建一个文件夹,我想为其授予写权限.但是我尝试执行此操作时遇到权限被拒绝错误

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 python:2.7
RUN pip install Flask==0.11.1 
RUN useradd -ms /bin/bash admin
USER admin
COPY app /app
WORKDIR /app
RUN chmod 777 /app
CMD ["python", "app.py"] 

我的错误是

PS C:\Users\Shivanand\Documents\Notes\Praneeth's work\Flask> docker build -t 
shivanand3939/test .
Sending build context to Docker daemon  209.9kB
Step 1/8 : FROM python:2.7
---> 8a90a66b719a
Step 2/8 : RUN pip install Flask==0.11.1
---> Using cache
---> 6dc114bd7cf1
Step 3/8 : RUN useradd -ms /bin/bash admin
---> Using cache
---> 1cfdb6eea7dc
Step 4/8 : USER admin
---> Using cache
---> 27c5e8b09f15
Step 5/8 : COPY app /app
---> Using cache
---> 5d628573b24f
Step 6/8 : WORKDIR /app
---> Using cache
---> 351e19a5a007
Step 7/8 : RUN chmod 777 /app
---> Running in aaad3c79e0f4
**chmod: changing permissions of ‘/app’: Operation not permitted
The command '/bin/sh -c chmod 777 /app' returned a non-zero code: 1**

如何授予对Docker容器内的应用文件夹的写权限

How can I give write permissions to app folder inside my Docker container

推荐答案

我想您正在切换为用户"admin",该用户无权更改/app目录的权限.使用"root"用户更改所有权.下面的Dockerfile为我工作-

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-尝试摆脱"777"权限.我暂时尝试在上述Dockerfile中做到这一点.

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

这篇关于如何在Docker容器内授予文件夹权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆