Skip to content

[Bug]: Postgres container fails to initialize when bind-mounting data directory due to permission errors on macOS #333

Closed

Description

@Kaikaikaifang

I have done the following

  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project

Steps to reproduce

container run \
  --env POSTGRES_PASSWORD=postgres \
  --env POSTGRES_USER=test \
  --env POSTGRES_DB=app \
  --mount type=bind,src=/host/etc/postgresql/data,dst=/var/lib/postgresql/data \
  --name test-postgres \
  -d postgres:16.8-alpine3.20

Current behavior

When running the official Postgres Docker container on macOS with a bind mount for the data directory, the container fails to initialize with permission errors:

chmod: /var/lib/postgresql/data: Operation not permitted
chown: /var/lib/postgresql/data: Operation not permitted

This causes the container to stop immediately after starting.

Expected behavior

  • The container should handle bind mounts on macOS gracefully, either by avoiding permission modifications that are not permitted or by documenting known limitations and workarounds.

  • Ideally, provide recommended best practices or guidance for macOS users mounting data directories to the Postgres container.

Environment

- OS: macOS 15.5
- Container: container CLI version 0.2.0 (build: release, commit: 3b5c253)

Relevant log output

❯ container run \
  --env POSTGRES_PASSWORD=postgres \
  --env POSTGRES_USER=test \
  --env POSTGRES_DB=app \
  --mount type=bind,src=/host/etc/postgresql/data,dst=/var/lib/postgresql/data \
  --name test-postgres \
  -d postgres:16.8-alpine3.20

test-postgres                 
❯ container logs test-postgres

chmod: /var/lib/postgresql/data: Operation not permitted
chown: /var/lib/postgresql/data: Operation not permitted

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. raxracks commented on Jul 14, 2025

    @raxracks

    I'm having the same issue on macOS 26 Beta 3 with the main branch (e09e932) using both --mount and --volume

  2. jglogan commented on Jul 16, 2025

    @jglogan
    Contributor

    @Kaikaikaifang @raxracks This is expected behavior for PostgreSQL and container. IIRC it may also be an issue for mySQL and MariaDB.

    With --volume/--mount in container, you're mounting exactly what you want to mount as a virtiofs share into your container. The problem occurs when you try to make your PG_DATA directory the same as the mount point, because virtiofs permissions are a little quirky there, and PostgreSQL, as you can see by your error messages, tries to modify permissions on the mount point and fails.

    What you're trying works in Docker because you're sharing all of your filesystem with the linuxkit VM that Docker runs. When you create the container, the actual mount point is somewhere below the virtiofs mount point, and that gets Linux bind mounted from the VM filesystem into your container's filesystem.

    As a workaround, try making your mount point /var/lib/postgresql:

    % rm -rf pgdata
    % mkdir pgdata
    % container run --name pgtest -e POSTGRES_PASSWORD=guest -v ${PWD}/pgdata:/var/lib/postgresql -d --rm postgres:latest
    pgtest                                                                                         
    % ls pgdata
    data
    %
  3. raxracks commented on Jul 16, 2025

    @raxracks

    Oh thanks that worked

  4. Kaikaikaifang commented on Jul 16, 2025

    @Kaikaikaifang
    Author

    LGTM! Thanks.

  5. Kaikaikaifang commented on Jul 16, 2025

    @Kaikaikaifang
    Author

    Before try /var/lib/postgresql instead of /var/lib/postgresql/data, you may need:

    container system stop
    container system start 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions