linux docker权限,linux – Docker:已安装卷的权限

我有这个图像,我从主机安装一个卷

-v /Users/john/workspace:/data/workspace

在容器内部,我使用的是不同于root的用户.现在问题是它无法在/ data / workspace内创建/修改文件(权限被拒绝).现在我解决了它现在在主机上做chmod -R 777工作区. Docker解决这个问题的方法是什么?

解决方法:

Managed to solve this using the new dockerfile args. It doesn’t require doing anything special after the container is built, so I thought I’d share. (Requires Docker 1.9)

In the Dockerfile:

# Setup User to match Host User, and give superuser permissions

ARG USER_ID=0

RUN useradd code_executor -u ${USER_ID} -g sudo

RUN echo 'code_executor ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER ${USER_ID}

Then to build:

docker build --build-arg USER_ID=$(id -u)

这样,容器中的用户可以写入已安装的主机卷(无需chown / chmod)

标签:docker,linux,permissions

来源: https://codeday.me/bug/20190609/1202068.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值