On Windows 10 Pro is always failed while docker-compose up, otherwise on mac is work perfectly.
Here are some my docker-compose file:
version: '2'
services:
.
.
.
.
postgresql:
image: postgres:93
container_name: lnpp-postgresql
restart: always
environment:
POSTGRES_PASSWORD: asdf
volumes:
- ./postgresql/data:/var/lib/postgresql/data
- ./postgresql/conf:/etc/postgresql/
ports:
- "5432:5432"
networks:
lnpp-network:
ipv4_address: ${lnpp_POSTGRES_IP}
networks:
lnpp-network:
driver: bridge
ipam:
driver: default
config:
- subnet: ${lnpp_SUBNET}
gateway: ${lnpp_GATEWAY}
and there are some logs.
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql exited with code 1
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql exited with code 1
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql | FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
lnpp-postgresql | HINT: The server must be started by the user that owns the data directory.
lnpp-postgresql exited with code 1
I have this same issue only on Windows. Everywhere else is fine.
The only way I was able to get around this was through a named volume mount:
postgresql:
image: postgres:93
volumes:
- postgres:/var/lib/postgresql/data
- ./postgresql/conf:/etc/postgresql/
...
volumes:
postgres:
Unfortunately, this is likely https://github.com/docker/for-win/issues/445, and there's not really anything we can do to fix it directly in the image. You might be able to work around it by messing with --user (user: in the compose YAML), but there are some caveats to that noted in https://hub.docker.com/_/postgres/.
Are there any updates on this issue? Here is a simple case to produce this error:
Compose file:
version: "3.7"
services:
postgres-test:
restart: always
image: postgres:latest
ports:
- "5432:5432"
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
volumes:
- ./postgres/data:/var/lib/postgresql/data/pgdata
Docker file:
FROM postgres:11.5-alpine
RUN mkdir -p "$PGDATA" && chmod -R 700 "$PGDATA" && chown -R postgres:postgres "$PGDATA"
I tried 1) changing the location of the data folder 2) running as root and 3) changing the ownership of the data folder. I can't use a named volume as others have suggested because I need to mount the data folder to a specific location on my server.
I have the same issue running:
docker run --name some-postgres -v E:\tmp\postgresBaza:/var/lib/postgresql/data -d postgres:9.6.15
I get from logs:
FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
Win10
version: '3.7'
services:
db:
image: postgres
volumes:
- ./postgres:/var/lib/postgresql/data
environment:
POSTGRES_DB: mydb
POSTGRES_USER: user
POSTGRES_PASSWORD: 123456
ports:
- 5432:5432
error:
running bootstrap script ... 2019-12-14 16:22:31.815 UTC [80] FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
I solved it!
version: '3.7'
services:
db:
image: postgres
ports:
- 5432:5432
restart: unless-stopped
volumes:
- pgdata:/var/lib/postgresql/data
- pgconf:/etc/postgresql
- pglog:/var/log/postgresql
environment:
POSTGRES_DB: mydb
POSTGRES_USER: myusername
POSTGRES_PASSWORD: 123456
adminer:
image: adminer
restart: always
ports:
- 8080:8080
volumes:
pgdata:
driver: local
pgconf:
driver: local
pglog:
driver: local
BUT environment doesn`t work, use default
u can check it on adminer - localhost:8080
user: postgres
password: postgres
Maybe there is a way to get around this using the userns-remap on the deamon? Must the docker image be "prepared" to use that feature?
I solved this by mapping my local volume one directory below the one Postgres needs:
version: '3'
services:
postgres:
image: postgres
restart: on-failure
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- PGDATA=/var/lib/postgresql/data/pgdata
- POSTGRES_DB=postgres
volumes:
- ./postgres_data:/var/lib/postgresql
ports:
- 5432:5432
This solution worked for me:
https://github.com/docker/for-win/issues/445#issuecomment-605572838
Most helpful comment
I solved this by mapping my local volume one directory below the one Postgres needs: