为什么 docker-compose 使用 user:group 999:999 创建目录/文件? [英] Why docker-compose creates directories/files with user:group 999:999?
问题描述
我使用 docker-compose up
和以下 docker-compose.yml
版本:'3.5'服务:mysql 服务器:图像:mysql:5.7环境:- MYSQL_ROOT_PASSWORD=root_pwd卷:- ./var/lib/mysql:/var/lib/mysql:rw
目录 ./var/lib/mysql
最初不存在.
运行docker-compose up
..
ls -al ./var/lib/mysql
命令显示所有带有 user:group
999:999
的文件.
我在我的系统中找不到名为 999
的用户或组.
为什么 docker-compose
选择使用不存在的 uid:gid创建文件?>
就我而言,除非我更改所有权,否则我无法提交特定目录.但即使我这样做,在下一次运行时,docker-compose up
再次将所有权更新为 999:999
.
以上问题的解决方法是什么?例如有没有办法指示 docker-compose 使用特定的 uid:gid 对映射主机中的文件?
主机:ubuntu-18.04
码头工人组成:1.22.0
Docker 用 mysql
镜像使用的用户创建并填充目录.当然,该用户在容器内有一个 uid
.uid
恰好是 999.
具有该 uid
的用户存在于容器中,但不存在于您的主机中.
在容器上,文件夹如下所示:
root@f86ffddac96c:/var/lib# ls -l共 32 个...drwxr-xr-x 5 mysql mysql 4096 Mar 19 13:06 mysql...
在主机上它最终看起来像这样.
root@machine:/home/username/mysql/var/lib# ls -l共 4 个drwxr-xr-x 5 999 docker 4096 Mar 19 15:06 mysql
这只是意味着用户 mysql
的 uid
为 999.当您创建从容器到主机的绑定卷时,该卷中的所有文件都必须具有相同的 uid
的相同权限.在我的测试机器上,docker 的 guid
为 999,这就是它在主机端显示的原因.
至于修复"这一点,您可以在 dockerfile 中使用(主机级别)已知的 uid
而不是默认的,或者您可以忽略它,因为它的工作方式与除非出于特定原因,您希望它在主机系统中为某个 uid
显示某个名称.
I used docker-compose up
with the following docker-compose.yml
version: '3.5'
services:
mysql-server:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=root_pwd
volumes:
- ./var/lib/mysql:/var/lib/mysql:rw
The directory ./var/lib/mysql
does not exist initially.
After running docker-compose up
..
ls -al ./var/lib/mysql
command shows all the files with user:group
999:999
.
I cannot find user or group called 999
in my system.
Why docker-compose
chooses to create files with a non-existing uid:gid ?
In my case, I cannot commit the specific directory unless I change ownership. But even when I do, on a next run, docker-compose up
updates the ownership again to 999:999
.
What is the solution to the above problem? e.g. Is there a way to instruct docker-compose to map files in host machine with a specific uid:gid pair?
Host: ubuntu-18.04
docker-compose: 1.22.0
Docker creates and populates the directory with the user that mysql
image uses. That user, of course, has an uid
within the container. That uid
happens to be 999.
The user with that uid
exists in the container but does not exist in your host.
On the container the folder looks like this:
root@f86ffddac96c:/var/lib# ls -l
total 32
...
drwxr-xr-x 5 mysql mysql 4096 Mar 19 13:06 mysql
...
and on the host it ends up looking like this.
root@machine:/home/username/mysql/var/lib# ls -l
total 4
drwxr-xr-x 5 999 docker 4096 Mar 19 15:06 mysql
This just simply means that the user mysql
has uid
of 999. And as you are creating a bind volume from container to host, all files within that volume must have same permissions for same uid
s. On my test machine docker has guid
of 999, which is why it is displayed as such on the host side.
As for "fixing" this you can either use a (host-level) known uid
in the dockerfile instead of the default one, or you can just ignore it, as it is working exactly as intended, unless there's a specific reason why you want it to display a certain name for a certain uid
in your host system.
这篇关于为什么 docker-compose 使用 user:group 999:999 创建目录/文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!