version: '3.9'
services:
db:
image: postgres
restart: always
ports:
- 5430:5432
volumes:
- my_pg_v:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=mydb
- POSTGRES_PASSWORD=mypass
- POSTGRES_USER=myuser
volumes:
my_pg_v:
networks:
default:
name: my_custom_network
This yields: postgres://myuser:mypass@localhost:5430/mydb
docker compose pull
- gets the lastest postgres imagedocker compose up
- runs the postgres database via Docker compose in the foreground (e.g. blocking)docker compose up -d
- runs the postgres database via Docker compose in the background (e.g. non-blocking). This blocks the PORT value too.
docker compose ps
-- see all docker compose services that are runningdocker ps
-- see all docker containers that are running (similar but different)
docker compose down
- stop + keep database data. Frees up the PORT value (regardless of how docker compose is running)docker compose down --rmi all -v
- DANGER - this will stop the database running AND delete all data.
docker compose -f compose.other.yaml
Anything after-f
needs to be a docker compose file. Consider using this for staging.
export PGPASSWORD=mypass
psql postgres://myuser@localhost:5430/mydb