Docker卷和主机权限 [英] Docker volume and host permissions

查看:91
本文介绍了Docker卷和主机权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,当我运行docker映像时,

When I run a docker image for example like

docker run -v /home/n1/workspace:/root/workspace -it rust:latest bash

我在容器中创建一个目录,例如

and I create a directory in the container like

mkdir /root/workspace/test

它由我的主机上的root拥有。这导致我必须在打开容器后每次都要更改权限才能使用该目录。

It's owned by root on my host machine. Which leads to I have to change the permissions everytime after I turn of the container to be able to operate with that directory.

有没有办法告诉Docker处理

Is there a way how to tell Docker to handle directories and files from my machine (host machine) point of view under a certain user?

推荐答案

确定,因为 Docker 使用 root 作为默认用户。您应该在Docker容器中创建用户,切换到该用户,然后创建文件夹,然后您将在主机上获得没有root权限的用户。

Sure, because Docker uses root as a default user. You should create user in your docker container, switch to that user and then make folder, then you will get them without root permissions on you host machine.

Dockerfile

FROM rust:latest
...
RUN useradd -ms /bin/bash myuser
USER myuser

这篇关于Docker卷和主机权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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