title: data lost while restarting postgres with docker
body: <p>I was running a postgres instance with following <code>docker-compose.yml</code>-</p>
  
  <pre><code>postgres:
    restart: always
    image: postgres:latest
    volumes:
      - /data:/var/lib/postgresql
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=123456
      - POSTGRES_DB=mydb
      - PGDATA=/var/lib/postgresql/data
  </code></pre>
  
  <p>I had added some tables with few rows.
  I made a small change in the file, adding <code>container_name: postgres</code>,
  and restarted with <code>docker-compose up -d</code></p>
  
  <p>and now when i login to the database, I don't see any tables/data.</p>
  
  <pre><code>psql -h ###### -p 5432 -d mydb -U admin --password
  </code></pre>
  
  <p>The data directory is added as volumes and is intact. </p>
  
  <p>Is it something to do with initializing postgres?</p>
  
  <p><strong>UPDATE 2016/10/02</strong></p>
  
  <p>Please note that <code>/data</code> is an external hard drive mounted on host <code>docker-machine</code>.</p>
  
  <p><strong>UPDATE 2016/10/02</strong></p>
  
  <p>Also I noticed that when I change the rename the location of <code>docker-compose.yml</code> (from <code>/home/ubuntu/dev/docker-storage/docker-compose.yml</code> to <code>/home/ubuntu/dev/storage/docker-compose.yml</code>), and do a <code>docker-compose up -d</code>, I get an error saying</p>
  
  <pre><code>ERROR: for postgres  Conflict. The name "/postgres" is already in use by container 6de8378a8156ec368748194f8912836a7b5e3212fbb69627093d0f6114b82f0d. 
  You have to remove (or rename) that container to be able to reuse that name.
  </code></pre>
  
  <p>Is that where problem is coming from? I might have removed the original container.</p>
  
  <p><strong>UPDATE 2016/10/06</strong></p>
  
  <p>This seems to be working now. For some weird reason, I had to mount both <code>/var/lib/postgresql</code> and <code>/var/lib/postgresql/data</code></p>
  
  <pre><code>postgres:
      restart: always
      image: postgres:latest
      container_name: postgres
      volumes:
        - /data/postgresql:/var/lib/postgresql
        - /data/postgresql/data:/var/lib/postgresql/data
      ports:
        - "5432:5432"
      environment:
        - POSTGRES_USER=admin
        - POSTGRES_PASSWORD=123456
        - POSTGRES_DB=mydb
  </code></pre>