title: Docker not recognizing Postgresql data directory
body: <p>I am desperately trying to get a Docker project I have inherited up and running, and Docker is giving me no end of problems. When trying to start up my containers I get the following error on my Postgresql container:</p>
  
  <pre><code>FATAL:  "/var/lib/postgresql/data" is not a valid data directory
  DETAIL:  File "/var/lib/postgresql/data/PG_VERSION" does not contain valid data.
  HINT:  You might need to initdb.
  </code></pre>
  
  <p>The project is a Rails project using Redis, ElasticSearch, and Sidekiq containers as well - those all load fine.</p>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>postgres:
    image: postgres:9.6.2
    environment:
      POSTGRES_USER: $PG_USER
      POSTGRES_PASSWORD: $PG_PASS
    ports:
      - '5432:5432'
    volumes:
      - postgres:/var/lib/postgresql/data
  </code></pre>
  
  <p><code>/var/lib/postgresql/data</code> is owned by the postgres user (as it should be I believe) and the postgresql service starts up and runs fine on its own.</p>
  
  <p>I have tried running <code>initdb</code> from the <code>/usr/lib/postgresql/9.6/bin</code> directory, as well as from docker (from docker it doesn't seem to persist or even create anything... if anyone knows why I would be interested in knowing)</p>
  
  <p>The contents of the <code>/var/lib/postgresql/data</code> directory: </p>
  
  <pre><code>drwxrwxrwx 19 postgres postgres  4096 Jun 28 20:41 .
  drwxr-xr-x  5 postgres postgres  4096 Jun 28 20:41 ..
  drwx------  5 postgres postgres  4096 Jun 28 20:41 base
  drwx------  2 postgres postgres  4096 Jun 28 20:41 global
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_clog
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_commit_ts
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_dynshmem
  -rw-------  1 postgres postgres  4468 Jun 28 20:41 pg_hba.conf
  -rw-------  1 postgres postgres  1636 Jun 28 20:41 pg_ident.conf
  drwx------  4 postgres postgres  4096 Jun 28 20:41 pg_logical
  drwx------  4 postgres postgres  4096 Jun 28 20:41 pg_multixact
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_notify
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_replslot
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_serial
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_snapshots
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_stat
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_stat_tmp
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_subtrans
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_tblspc
  drwx------  2 postgres postgres  4096 Jun 28 20:41 pg_twophase
  -rw-------  1 postgres postgres     4 Jun 28 20:41 PG_VERSION
  drwx------  3 postgres postgres  4096 Jun 28 20:41 pg_xlog
  -rw-------  1 postgres postgres    88 Jun 28 20:41 postgresql.auto.conf
  -rw-------  1 postgres postgres 22267 Jun 28 20:41 postgresql.conf  
  </code></pre>
  
  <p><code>PG_VERSION</code> contains 9.6</p>
  
  <p>Any help is much appreciated.</p>