docker-compose postgres volume 将所有权更改为 gitlab-runner

docker-compose postgres volume changes ownership to gitlab-runner

我遇到了一个很奇怪的问题,找不到为什么会这样。几个月前,我在我的电脑上安装了 gitlab-运行ner,也许一年前就不再使用它了。

我有一个docker-composer.yml:

version: '2'

services:
  db:
    image: postgres:9.5
    #restart: always
    environment:
      POSTGRES_PASSWORD: password
    volumes:
      - ./storage:/var/lib/postgresql/data

我创建 ./storage,ls 给我:

drwxrwxr-x 2 pierre-emmanuel pierre-emmanuel 4096 jui 31 23:33 storage

当我 运行 docker-compose up -d 时,用户更改为 gitlab-runner ...我完全不明白这一点。它不应该发生。

这是 ls 我有:

drwx------ 19 gitlab-runner   pierre-emmanuel 4096 jui 31 23:35 storage

现在我重复了这个并且 ps -aux | grep gitlab 能够看到这个:

gitlab-+  2404 11.5  0.0  19704  3456 ?        Ss   23:34   0:00 bash /usr/local/bin/docker-entrypoint.sh postgres
gitlab-+  2514  6.0  0.0  19904  3912 ?        S    23:35   0:00 initdb --username=postgres --pwfile=/dev/fd/63
gitlab-+  2536  0.0  0.0   4280   712 ?        S    23:35   0:00 sh -c "/usr/lib/postgresql/9.5/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 >/dev/null
gitlab-+  2537  0.0  0.3 281888 28572 ?        R    23:35   0:00 /usr/lib/postgresql/9.5/bin/postgres --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1

然后一直这样直到我调用docker-composer stop:

gitlab-+  2404  0.0  0.2 274528 23304 ?        Ss   23:34   0:00 postgres
gitlab-+  2618  0.0  0.0 274528  3780 ?        Ss   23:35   0:00 postgres: checkpointer process  
gitlab-+  2619  0.0  0.0 274528  5400 ?        Ss   23:35   0:00 postgres: writer process  
gitlab-+  2620  0.0  0.0 274528  3780 ?        Ss   23:35   0:00 postgres: wal writer process  
gitlab-+  2621  0.0  0.0 274956  6252 ?        Ss   23:35   0:00 postgres: autovacuum launcher process  
gitlab-+  2622  0.0  0.0 129512  2828 ?        Ss   23:35   0:00 postgres: stats collector process

我自己的用户和 gitlab-runner 确实有 docker 组,但我不明白为什么会这样。你有什么想法吗?

编辑:当我删除应用程序时,从 docker-compose.yml 中删除音量并重新创建应用程序,用户 gitlab-运行ner 仍然习惯于 运行 包含postgres的容器。

进程和文件由 numeric 用户和组 ID 拥有。有一个文件 /etc/passwd,在用户名和用户 ID 之间进行映射;但是 Docker 的本质是每个容器都有自己独立的文件系统 space,这意味着它有自己的 /etc/passwd 文件。

如果您查看 the Docker Hub postgresql page there is a link to the image's Dockerfile,您会发现其中包含一个命令

RUN useradd ... --uid=999 ... postgres

您应该能够验证本地系统和容器内的用户 ID 是否匹配

grep gitlab-runner /etc/passwd
docker run --rm postgres:9.5 grep postgres /etc/passwd

我希望这两个在第三个字段中显示 999 的 uid。这些文件归该 uid 所有,但它恰好在容器内外转换为不同的名称。