Docker + postgres

I am using M2 chip.
Docker version 24.0.5

version: "3.5"


      - "5432:5432"
    container_name: "${LOCALSTACK_DOCKER_NAME-pgsql2}"
    image: postgres:15.3
    restart: always
      POSTGRES_PASSWORD: password
      PGDATA: "/data/postgres"
      - "./postgres:/data/postgres"
      - "./dump.sql:/docker-entrypoint-initdb.d/dump.sql"
    user: ${UID}:${GID}

This is my docker compose file. I want to initialize database while running the container.
I am getting this error while doing docker-compose up pgsql2

initdb: error: could not change permissions of directory “/data/postgres”: Operation not permitted
pgsql2 | fixing permissions on existing directory /data/postgres …

Tried most of solution like changing image or using named volumes.
Any help is appreciated!

Your post is in the Community category, which is used to inform us about community events or ask about them. Please let us know how your topic is related to the category.

I moved the topic to the compose category before reading @meyay’s post, but I’m pretty sure it was nothing to do with the community. I mean the whole website is for questions answared by the community, but the question is not about the community,

I think you should just read the image description more carefully: postgres
You set the PGDATA to the moint point while the descriptions recommends mounting the parent folder not data


Important Note: when mounting a volume to /var/lib/postgresql, the /var/lib/postgresql/data path is a local volume from the container runtime, thus data is not persisted on the mounted volume.

You probably can’t change the ownership of the moint point.

1 Like