Created
June 17, 2020 20:11
-
-
Save rponte/c3637d488b38ce0c39df76d2c6b34f79 to your computer and use it in GitHub Desktop.
Docker-compose: PostgreSQL and PgAdmin
This file contains hidden or 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
| # Use postgres/example user/password credentials | |
| version: '3.1' | |
| services: | |
| db: | |
| image: "postgres:10.6" | |
| restart: always | |
| ports: | |
| - 5432:5432 | |
| environment: | |
| POSTGRES_USER: ${POSTGRES_USER:-postgres} | |
| POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme} | |
| volumes: | |
| - database-data:/var/lib/postgresql/data/ # persist data even if container shuts down | |
| - ./bootstrap:/docker-entrypoint-initdb.d | |
| pgadmin: | |
| image: adminer | |
| restart: always | |
| ports: | |
| - 8080:8080 | |
| volumes: | |
| database-data: # named volumes can be managed easier using docker-compose |
Author
Author
Running PostgreSQL 13.x container via command line:
docker run --name cdc-postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d postgres:13.3We can start and stop the container as well:
docker container start cdc-postgres
docker container stop cdc-postgres
Author
Running pg_activity to monitoring Postgres instance:
Just run the commands below to install in the container where the postgres is running:
docker-compose exec <pg_server_name> bash # or docker exec -i -t postgres bash
apt update && apt install pg-activity && pg_activity -U postgresFor more details, see this Reddit comment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

You can use this SQL script in the
bootstrapfolder to create a new user on container's startup:And also you can import a database via Docker command (or Docker-compose as well):