Skip to content
  • Emanuele Aina's avatar
    docker-compose: Move PGDATA to a subdir to make permissions work out-of-the-box · 9cf9983c
    Emanuele Aina authored
    We currently bind mount `/var/lib/postgresql/data` to a local folder
    which is assumed to exist with the right permissions, owned by the user
    under which the `postgres` container is run (uid 1000 or the one
    configured with the `RUN_USER` environment variable).
    
    If that's not the case (on a fresh checkout, for instance), you'll
    be left staring at the following error, after the container failed
    to start:
    
        fixing permissions on existing directory /var/lib/postgresql/data ... initdb: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
    
    Having things not work out of the box with weird errors is annoying and
    can easily lead to a non-trivial amount of wasted time (hello!).
    
    This is because Docker creates the mount point directories as owned by
    root, so when the Postgres' `initdb` runs as the `postgres` user it
    fails to change the ownership of the directory.
    
    Shipping the empty directory in...
    9cf9983c