-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chmod: changing permissions of 'var/lib/postgresql/data': Permission denied #116
Comments
Hi, edited: |
If you are using MacOSX or Windows with the Vbox shared folders, then this is a duplicate of #28 |
Hey, guys! docker run \
--name my-postgres \
-e POSTGRES_USER=admin \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=some_db_dev \
-v $PG_LOCAL_DATA:/var/lib/postgresql/data \
-d postgres:9.5.1
My output is the following:
Versions of docker, docker-machine, virtualbox and boot2docker are:
I saw many publications about this topic but the most of them are outdated. I had tried do the same solution as for mysql but it did not help. Maybe somebody can updated me: does some solution exist to run postgres container with data volumes through docker-machine? Thanks! |
Any workarounds for this? |
I'm experiencing the same error when trying to run the latest image on OpenShift Enterprise. The error occurs whether the container has or does not have a mounted volume:
|
Hi, Found this for solving the chmod issue: Check here too for the selinux security issue : I fixed my docker-compose file by adding a :z at the end of the volume command Hope it will help. |
I'm noticing that the |
@collinpeters, it looks like we only chown to the user in the entrypoint. |
any news about this issue? |
My issue appears like that of @sergio1990 except that I am using "Docker for Mac" instead of "Docker Toolbox". I resolved my case by changing ownership of the host file system to be used by the PostgresQL container to the $USER who will run that container. In doing so it appeared that the container relies upon the credentials cache resulting from the ownership change: |
I have been trying to apply the
Note that I have tried the mountPath with both apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sonar-postgres
spec:
replicas: 1
template:
metadata:
labels:
app: sonar-postgres
tier: backend
spec:
containers:
- name: sonar-postgres
image: postgres:9.6
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: sonar-postgres
key: user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: sonar-postgres
key: password
ports:
- name: postgresport
containerPort: 5432
volumeMounts:
- name: sonar-postgres-data
mountPath: /var/lib/postgresql/data:z
volumes:
- name: sonar-postgres-data
persistentVolumeClaim:
claimName: sonar-postgres
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: sonar-postgres
labels:
app: sonar
tier: backend
spec:
capacity:
storage: 500Mi
accessModes:
- ReadWriteMany
nfs:
server: x.x.x.x
path: /kubernetes/volumes/sonar/postgres
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sonar-postgres
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Mi |
@marcofranssen have same issue with kubernetes deployment. |
…d in docker-library/postgres#116 (comment) . This is the simpler way for docker >1.7, otherwise we would have to tweek with the chcon command.
For anyone still experiencing this (I am, using Docker for Windows. This is my first google result for the permissions error), I discovered a workaround that works for my case (I'm using it for an end-to-end test so I don't need to persist data, unsure how this workaround interacts with volumes). All I'm doing is setting the
|
FYI: You can't have your db in Change that path by See https://stackoverflow.com/questions/50916801/kubernetes-pod-which-encapsulates-db-is-crashing |
I want to update this issue because I think people are still hitting it via google. I don't think you should add "no_root_squash" to your exports. The answer is in https://hub.docker.com/_/postgres.
So if you set the environment variable PGDATA to Your container will mount /var/lib/postgresql/data and create the pgdata directory. All of the chown operations will work because it's not trying to chown the base directory (which is the nfs mount). |
@shewless don't work in OKD 3.11 with psql 11 |
…#116 (comment)) Fix issue with values in env files Buddy Michael Chan
For anyone still get this issue. I get the "permission deined" while mapping volume in docker using kubernestes. I tried so many ways to fix this like "chmod , chown ..." , but nothing works. |
I received this error message
Reason: Mount path of my volume and PGDATA was both set to /var/lib/postgresql/data When i changed PGDATA to /var/lib/postgresql/data/mydata the issue was resolved.
|
On the off-chance that someone else is struggling with this ... I'm running inside Vagrant, and I had endless problems mounting postgres with a data volume explicitly set. Turns out it's Vagrant. |
Still experiencing errors while using Docker Desktop for MacOS for PostgreSQL. The compose file looks like version: "3.7"
services:
db:
image: postgres:12
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: db
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- /home/docker/volumes/db:/var/lib/postgresql/data
networks:
- backend
ports:
- 5432:5432
deploy:
placement:
constraints: [node.role == manager] Notice The error reports:
Looking forward to your many helps. |
@shukriadams Could you please explicitly explain what you did to fix? |
@Dhanabalan89 Could you please post your docker command? |
This comment has been minimized.
This comment has been minimized.
Hi, i had got the same error
|
@FatihMert1 |
This got it to work in my WSL2 environment. But obviously, it should have been
|
ohh yes, its my fault, that's actually PGDATA, thank you for comment |
But in your yaml - in a env PGDATA there is a different path, unlike the connected volume - and volume created empty, i think it work because pginit work not correct with volume connectend in windows (I used WSL too) |
db:
container_name: pg_container
build:
context: ./postgres
dockerfile: $PWD/postgres/postgresql_dockerfile
environment:
PGDATA: /var/lib/pg_data
volumes:
- ./postgres/data:/var/lib/postgresql/data (focused yaml from #116 (comment) above) ☝️ Just a quick word of caution. Although I don't know what is happening in the used Dockerfile, if this is based upon any of the |
On macos changing the PGDATA to |
This worked for me..GREAT..ur rockstar |
docker-library/postgres#116 (comment) Co-authored-by: Eugene O'Fallon <epofallon@gmail.com> Co-authored-by: Aaron Hull <aahull08@gmail.com> Co-authored-by: Marcin Kostecki <49038365+marcinkostecki@users.noreply.github.com>
Using 'mountPath: /var/lib/postgresql/data:z' in k8s yaml made it create a path of '/var/lib/postgresql/data:z', instead of 'mountPath: /var/lib/postgresql/data' with right permissions. |
Re: k8s mounts and selinux labels: https://stackoverflow.com/a/51026623/433558 |
tried few suggestions I saw in this thread. I have a directory in my C drive called data so "C:\data" But what i found with this exact erros "[chmod: changing permissions of 'var/lib/postgresql/data': Permission denied]" in my postgres compose mounted the pgdata to a directory and not a volume map (which for this test i wanted to do that) to no avail, and as soon as i moved the docker-compose-data directory i tried to mount posgres into, to eg. my wsl user home directory "~/" and i ran docker compose up the db init script ran with no errors till completion. |
What worked for me First get the user you use to run the docker compose
Now copy paste those values inside of the docker compose.
A lot of solutions proposed hereabove are not persisting data in the volume, which is not really useful. |
Nice |
For me, with my docker-compose.yml file having:
I was just missing the
Section/volume definition at the end. Don't know if this is a very case-speciffic solution, but just leaving it here if it is useful for someone |
Hitting the same error still. I'm following the instruction for ❯ docker run -d \
--name some-postgres \
-e POSTGRES_PASSWORD=mysecretpassword \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v "${PWD}/mount:/var/lib/postgresql/data" \
postgres
fc351129b480a4a7b84d5b9eebcf0b7ec05845d72da9febf4a15818b55498c83
docker: Error response from daemon: error while creating mount source path '/Users/janexing/my_path/tmp/mount': chown /Users/janexing/my_path/tmp/mount: permission denied.
❯ ls -la
total 0
drwxrwxrwx@ 3 janexing staff 96 Dec 7 14:57 .
drwxr-xr-x 48 janexing staff 1536 Dec 7 14:32 ..
drwxr-xr-x@ 2 janexing staff 64 Dec 7 14:57 mount
❯ chmod 777 ./mount
❯ ls -la
total 0
drwxrwxrwx@ 3 janexing staff 96 Dec 7 15:00 .
drwxr-xr-x 48 janexing staff 1536 Dec 7 14:32 ..
drwxrwxrwx@ 3 janexing staff 96 Dec 7 15:01 mount
❯ docker run -d \
--name some-postgres \
-e POSTGRES_PASSWORD=mysecretpassword \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v "${PWD}/mount:/var/lib/postgresql/data" \
postgres
❯ docker logs some-postgres -f
chown: changing ownership of '/var/lib/postgresql/data/pgdata': Permission denied Oddly, if I try to bind
OS: MacOS 13.6.1 (22G313) |
I would suggest setting the UID/GID of the container to match the one on your host ( |
I encountered the following error as well:
In my case, I resolved it by fixing the volume path from:
to:
I'm sharing this here in case it might help someone else. |
I made it work for mac + minikube with this minikube setup# it doesn't work without the --uid and --gid params
$ minikube mount ./my-app/postgres-data:/postgres-data --uid=999 --gid=999 ymlapiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 10Gi
hostPath:
path: /postgres-data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
spec:
accessModes:
- ReadWriteOnce
volumeName: postgres-pv
storageClassName: ""
resources:
requests:
storage: 10Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
serviceName: postgres
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:16
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 5432
resources:
limits:
memory: "512Mi"
cpu: "500m"
requests:
memory: "64Mi"
cpu: "500m"
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-secret
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: POSTGRES_PASSWORD
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-data
persistentVolumeClaim:
claimName: postgres-pvc |
Unfortunately that didn't work for me as well:
|
I have slightly extended the official postgres Image in the following way (only the COPY is really important, to do some stuff to use SonarQube with Postgres):
Version: 1.0.0
FROM postgres:9.5
MAINTAINER Wolfgang Grossinger "wolfgang.grossinger@gmail.com"
COPY sonarqube.sql /docker-entrypoint-initdb.d
RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
ENV POSTGRES_PASSWORD=postgres
ENV POSTGRES_USER=postgres
RUN chmod 777 /var/lib/postgresql/data
After building the image I try to start it with the following command:
sudo docker run --name postgres_sonar -p 5432:5432 -v /data:/var/lib/postgresql/data wogro/postgres_sonar
I get the following error message:
chmod: changing permissions of ‘/var/lib/postgresql/data’: Permission denied
I don't know what the reason is (probably it's me), but it is something i would never expect from an official image (I just would expect that mounting a volume works :-))
The text was updated successfully, but these errors were encountered: