Skip to content

rootless container permission error #1287

Open
@emperorkebab

Description

@emperorkebab

Creating a container with "user:1000:1000" in the compose file generates these errors:

chmod: /var/lib/postgresql/data: Operation not permitted
chmod: /var/run/postgresql: Operation not permitted
The files belonging to this database system will be owned by user "myrootlessuser".
This user must also own the server process.

...

fixing permissions on existing directory /var/lib/postgresql/data ... initdb: error: could not change permission of directory "/var/lib/postgresql/data": Operation not permitted

This seems to happen because i'm using a subuid (which the volume correctly chowns to the bind path)

A solution to this could be to let us set the postgres user UID and GID manually, as suggested in #1068

This works without using subuids, but doesn't if so:

services:
  pgdbex:
    image: postgres:16-alpine
    cap_drop:
      - ALL
    user: 1000:1000
    environment:
      POSTGRES_USER: 
      POSTGRES_PASSWORD: 
      POSTGRES_DB: 
    volumes:
      - ./db:/var/lib/postgresql/data 

This doesn't work in either case:

services:
  pgdbex:
    image: postgres:16-alpine
    cap_drop:
      - ALL
    user: 1000:1000
    environment:
      POSTGRES_USER: 
      POSTGRES_PASSWORD: 
      POSTGRES_DB: 
    volumes:
      - pgdbdata:/var/lib/postgresql/data 

volumes:
  pgdbdata:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: ./db

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions