anotherdev
anotherdev

Reputation: 2569

docker-compose postgres volume changes ownership to gitlab-runner

I have a very strange problem, and cannot find why this happens. I installed gitlab-runner on my computer a several months ago, maybe a year and didn't use it anymore .

I have a docker-composer.yml:

version: '2'

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

I create ./storage, a ls gives me:

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

When I run docker-compose up -d , the user is changed to gitlab-runner ... I don't understand this AT ALL. It should have never happened.

Here is the ls I have:

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

Now I repeated this and with ps -aux | grep gitlab was able to see this:

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

Then after it stays like this until I call 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

My own user and gitlab-runner do have the docker group, but I can't figure out why this is producing. Do you have any idea ?

EDIT: when I remove the app, remove the volume from docker-compose.yml and re-create the app, the user gitlab-runner is still used to run the container which contains postgres.

Upvotes: 1

Views: 578

Answers (1)

David Maze
David Maze

Reputation: 158748

Processes and files are owned by numeric user and group IDs. There's a file, /etc/passwd, that maps between user names and user IDs; but the nature of Docker is that each container has its own isolated filesystem space, which means it has its own /etc/passwd file.

If you look at the Docker Hub postgresql page there is a link to the image's Dockerfile and you can see that includes a command

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

You should be able to verify that the user IDs on your local system and inside the container match up

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

I would expect both of these to show a uid of 999 in the third field. The files are owned by that uid, but it happens to translate to a different name inside and outside the container.

Upvotes: 1

Related Questions