Basically I have this postgres image:
1 FROM postgres:latest
1 COPY deployment/postgres_init /docker-entrypoint-initdb.d
2 USER 999
3 RUN initdb
4 CMD postgres -c hba_file=docker-entrypoint-initdb.d/pg_hba.conf -c config_fi le=docker-entrypoint-initdb.d/postgresql.conf
and this postgres deployment with volumeMount:
1 apiVersion: apps/v1
1 kind: Deployment
2 metadata:
3 name: postgres-deployment
4 spec:
5 replicas: 1
6 selector:
7 matchLabels:
8 component: postgres
9 template:
10 metadata:
11 labels:
12 component: postgres
13 spec:
14 securityContext:
15 runAsUser: 999
16 volumes:
17 - name: postgres-storage
18 persistentVolumeClaim:
19 claimName: postgres-persistent-volume-claim
20 containers:
21 - name: postgres
22 image: prikshet/postgres
23 ports:
24 - containerPort: 5432
25 volumeMounts:
26 - name: postgres-storage
27 mountPath: /var/lib/postgresql/data
28 subPath: postgres
29 imagePullPolicy: Always
When I remove volumeMount there’s no error, but if I add volumeMount then I get the following:
2021-08-10 15:07:33.911 GMT [9] LOG: skipping missing configuration file "/var/lib/postgresql/data/postgresql.auto.conf"
2021-08-10 15:07:33.911 UTC [9] FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
2021-08-10 15:07:33.911 UTC [9] HINT: The server must be started by the user that owns the data directory.
You’d think that runAsUser: 999 in the yaml and USER 999 in the dockerfile would work, but it doesn’t. How to fix this?