postgis / docker-postgis

Docker image for PostGIS
https://hub.docker.com/r/postgis/postgis/
MIT License
1.39k stars 466 forks source link

(Mac+VFS) data directory "/var/lib/postgresql/data" has wrong ownership #361

Closed daweimau closed 11 months ago

daweimau commented 1 year ago

Given the below docker-compose yml:

version: "3.7"

services:
    db:
        container_name: db
        image: postgis/postgis:15-3.4-alpine
        ports:
            - "5010:5432"  
        environment:
            POSTGRES_DB: my-db
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: verysecretpass
        volumes:
            - ./pgdata:/var/lib/postgresql/data 
db  | 2023-09-17 01:22:45.415 UTC [1] FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
db  | 2023-09-17 01:22:45.415 UTC [1] HINT:  The server must be started by the user that owns the data directory.

But it works with the postgres alpine image. Why should it not work now?

Seeing as we extend the postgres-alpine image, and postgres-alpine works, I figured we must be introducing the problem after the base image layers / entrypoint.

    db:
        container_name: db
        build:
            context: "./pg"
            dockerfile: "./Dockerfile"
        ports:

Since doing so, the data directory "/var/lib/postgresql/data" has wrong ownership error has disappeared.

I don't understand the details. But I believe the initdb-postgis.sh script is doing it

ImreSamu commented 1 year ago

Thank you for reporting this issue!

To better assist you, could you provide more details about:

By the way, what exact filesystem do you have under the volume? ( ./pgdata: )

For instance, postgres doesn't work for others under Mac/VirtioFS either.

Please try using "docker volume" as a workaround. It has solved the problem for many.

Please also check the related issues in the

If we replace image with postgres:alpine, we have no issues. Everything works.

Please also replace the data dir ( ./pgdatapostgres01: vs. ./pgdatapostgis02: ) and check the logs for the initialization process.
Please share both logs so we can check.

I don't understand the details. But I believe the initdb-postgis.sh script is doing it

There are two initialization steps, which can be challenging to debug. Please share your initialization logs with us.

Or you can replace/remove the postgis initialization with a dummy script, so the original 10_postgis.sh is not running.

daweimau commented 1 year ago

os

Mac M1 pro sillicon
macOS Ventura 13.5.1
Docker 4.11.0 

Thanks for your links. Reading them made me more suspicious of my workaround. I've since confirmed:

The behaviour can be quite intermittent so I will come back if my observation changes; I will continue with 4.23+VFS

ImreSamu commented 11 months ago

The behaviour can be quite intermittent so I will come back if my observation changes; I will continue with 4.23+VFS

I am closing this issue. However, if there is any important matter that was overlooked, please let me know and I will reopen the issue.