Last active
January 18, 2022 17:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
~/bin/docker-volume-cp
: https://gist.github.com/mrsarm/6713bfd973c2338ddada12e53487886f