在Windows中使用附加的卷更改正在运行的Docker容器中的文件的所有者 [英] Change the owner of a file in a running Docker container with an attached volume in Windows

查看:315
本文介绍了在Windows中使用附加的卷更改正在运行的Docker容器中的文件的所有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows中运行Docker(不是我没有Windows Pro的本机版本)。



我正在运行带有附加卷的图像使用Docker Quickstart终端(MinGW64)(我也使用Windows命令提示符):

  docker run --rm -it -v / c / Users / yahya / example:/ host-shared debian bash 

当我运行 ls -l <​​/ code>在 / host-shared 目录中我得到:

 总计0 
drwxrwxrwx 1 1000人员0 8月6日20:38 hi

但是,当我尝试更改此文件的所有者时,如下所示:

  chown www-data: www-data hi 

,运行 ls -l <​​/ code>再次所有者没有改变!



我相信这可能只是一个Windows问题。

解决方案

我刚刚测试了(在Linux上),它实际上是有效的。它可能无法按预期或需要它工作,但它可以正常工作。



容器中的文件属于用户 www-data: www-data ,对于主机,它属于用户 1:33



如果主机和容器用户不匹配,那么这是因为容器和主机之间的UID和GID不同。解决方案是使用 useradd --uid $ HOST_USER_UID --gid $ HOST_USER_GID $ USER_NAME 创建一个用户,然后设置!






更新



这是已发出的命令:

  root @ 5665d3b794a2:/#ls -lh host-shared / aklm / 
total 0
-rw-rw-r--。 1 www-data www-data 0 Aug 6 07:03 aze
-rw-rw-r--。 1 www-data www-data 0 Aug 6 07:03 azer
root @ 5665d3b794a2:/#chown -R root:root / host-shared /
root @ 5665d3b794a2:/#ls -lh host-共享/ aklm /
总共0
-rw-rw-r--。 1根root 0 Aug 6 07:03 aze
-rw-rw-r--。 1根根0 8月6日07:03 azer

Docker服务器版本:1.11.2


I am running Docker in Windows (not the native version as I don't have Windows Pro).

I am running a image with an attached volume like so using the Docker Quickstart terminal (MinGW64) (I also used Windows Command Prompt):

docker run --rm -it -v /c/Users/yahya/example:/host-shared debian bash

When I run ls -l on the /host-shared directory I get this:

total 0
drwxrwxrwx 1 1000 staff 0 Aug  6 20:38 hi

However when I try to change the owner of this file like so:

chown www-data:www-data hi 

and the run ls -l again; the owner has not changed!

I believe this may be a Windows only problem.

解决方案

I just tested it (on Linux though) and it actually works. It may not work as you expect or need it, but it does work.

The files in the container belongs to the user www-data:www-data, as for the host, it belongs to the user 1:33.

If the host and container users do not match then it is because the UID and GID differs between the container and the host. The solution is to create a user using useradd --uid $HOST_USER_UID --gid $HOST_USER_GID $USER_NAME, then you're set!


Update

Here is the issued commands:

root@5665d3b794a2:/# ls -lh host-shared/aklm/
total 0
-rw-rw-r--. 1 www-data www-data 0 Aug  6 07:03 aze
-rw-rw-r--. 1 www-data www-data 0 Aug  6 07:03 azer
root@5665d3b794a2:/# chown -R root:root /host-shared/
root@5665d3b794a2:/# ls -lh host-shared/aklm/
total 0
-rw-rw-r--. 1 root root 0 Aug  6 07:03 aze
-rw-rw-r--. 1 root root 0 Aug  6 07:03 azer

Docker Server Version: 1.11.2

这篇关于在Windows中使用附加的卷更改正在运行的Docker容器中的文件的所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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