I was running a postgres instance with following docker-compose.yml-
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
I had added some tables with few rows.
I made a small change in the file, adding container_name: postgres,
and restarted with docker-compose up -d
and now when i login to the database, I don't see any tables/data.
psql -h ###### -p 5432 -d mydb -U admin --password
The data directory is added as volumes and is intact.
Is it something to do with initializing postgres?
UPDATE 2016/10/02
Please note that /data is an external hard drive mounted on host docker-machine.
UPDATE 2016/10/02
Also I noticed that when I change the rename the location of docker-compose.yml (from /home/ubuntu/dev/docker-storage/docker-compose.yml to /home/ubuntu/dev/storage/docker-compose.yml), and do a docker-compose up -d, I get an error saying
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.
Is that where problem is coming from? I might have removed the original container.
UPDATE 2016/10/06
This seems to be working now. For some weird reason, I had to mount both /var/lib/postgresql and /var/lib/postgresql/data
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