title: Permission issue with PostgreSQL in docker container
body: <p>I'm trying to run a docker image with PostgreSQL that has a volume configured for persisting data.</p>
  
  <h3>docker-compose.yml</h3>
  
  <pre><code>version: '3.1'
  
  services:
    db:
      image: postgres
      restart: always
      volumes:
        - ./data:/var/lib/postgresql/data
      environment:
        POSTGRES_PASSWORD: example
  </code></pre>
  
  <p>When I start the container I see the output</p>
  
  <blockquote>
    <p>fixing permissions on existing directory /var/lib/postgresql/data ... ok</p>
  </blockquote>
  
  <p>and the data folder is no longer readable for me.</p>
  
  <p>If I elevate myself and access the data directory I can see that the files are there. Furthermore, the command <code>ls -ld data</code> gives me </p>
  
  <pre><code>drwx------ 19 systemd-coredump root 4096 May 17 16:22 data
  </code></pre>
  
  <p>I can manually set the directory permission with <code>sudo chmod 755 data</code>, but that only works until I restart the container.</p>
  
  <p>Why does this happen, and how can I fix it?</p>