Skip to content

Instantly share code, notes, and snippets.

@mrsarm
Last active January 18, 2022 17:02
Show Gist options
  • Save mrsarm/984a6f69978349ceec020028714a35f8 to your computer and use it in GitHub Desktop.
Save mrsarm/984a6f69978349ceec020028714a35f8 to your computer and use it in GitHub Desktop.
docker-compose.yml pg-latest: launch a PostgreSQL server with a volume attached to persist data across sessions
version: "3.9"
services:
pg-latest:
container_name: pg-latest
image: postgres
environment:
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
volumes:
- data:/var/lib/postgresql/data
command: ["postgres", "-c", "log_statement=all"] # Comment to disable SQL logs. all: all queries, ddl: DDL only, mod: DDL and modifying statements
psql:
image: postgres
command: psql postgres -h pg-latest -U postgres -W
depends_on:
- pg-latest
profiles: # To avoid the container start with `docker-compose up'
- tools
volumes:
data: # Volume name listed: pg-latest_data
driver: local
# - `docker-compose up' to start postgres attached to the console. Add `-d' option
# to start the container detached
# - Connect with `docker-compose run psql`. To pass more options to `psql' use:
# `docker-compose run pg-latest psql postgres -h HOSTIP -U postgres -W [OPTIONS...]'
# - Run any pg_* command available in the container, e.g.
# `docker-compose run pg-latest pg_dump [OPTIONS]`
# - `docker-compose stop' to stop the service if it was detached,
# otherwise just press Ctrl+C to stop
# - `docker-compose down' to shutdown and drop the container (the data will continue
# stored in the 'pg-latest_data' volume)
# - `docker volume rm pg-latest_data' to drop the data from the volume (first
# execute `docker-compose down')
# - `~/bin/docker-volume-cp pg-latest_data pg-latest_data-backup-$(date --iso-8601)'
# to backup the DB to a new volume
@mrsarm
Copy link
Author

mrsarm commented Sep 1, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment