version: "3"
services:
db:
image: "postgres"
container_name: "my_postgres"
ports:
- "54320:5432"
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: 'postgres'
volumes:
db_data:
docker-compose up
Or pass -d
if you want to run this container as demonize
docker exec -e PGPASSWORD=db-password -it my_postgres pg_dump --no-acl --no-owner -h host-name --dbname=dbname --table=table-name --data-only --user=username > ../databases/table-name.dump
In above command we are passing PGPASSWORD
postgresql password as docker container's environment variable. If we don't pass
password like this, then pg_dump
command will prompt for password which is not prompted in cli, and above command might not be successful.
docker cp ../databases/latest.dump my_postgres:/latest.dump
docker exec -it my_postgres psql -U postgres
> create database po_app_dev;
> \q
docker exec -it my_postgres pg_restore --verbose --clean --no-acl --no-owner -h -U postgres localhost -d po_app_dev /latest.dump
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my_postgres