Postgresql
Dockerized PostgreSQL database server.
Directory Structure
Container directory structure
container_root/
../pg_entrypoint
../pg_entrypoint.sh
../.env
../.gitignore
../docker-compose.yml
Container Files
.env
docker-compose.yml
postgresql docker-compose.yml
---
volumes:
postgres_data:
pgadmin_data:
networks:
pg_net:
services:
postgres:
image: postgres:${POSTGRES_IMAGE_TAG:-bullseye}
container_name: ${POSTGRES_CONTAINER_NAME:-postgres}
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
# Read section on this variable in docker docs before setting:
# https://hub.docker.com/_/postgres/
POSTGRES_HOST_AUTH_METHOD: ${POSTGRES_HOST_AUTH_METHOD}
expose:
- 5432
ports:
- ${POSTGRES_PORT:-5432}:5432
volumes:
- ${POSTGRES_DATA_DIR:-postgres_data}:/var/lib/postgresql/data
# Mount directory with init scripts for docker, i.e. install UUID extension
- ./pg_entrypoint:/docker-entrypoint-initdb.d/
# Mount directory to store SQL scripts
- ${POSTGRES_SCRIPTS_DIR:-./pgsql_scripts}:/scripts
# Uncomment line below to restore a database backup.
# - ${POSTGRES_DB_BACKUP}:/path/here
networks:
- pg_net
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 1s
timeout: 5s
retries: 10
pgadmin:
image: dpage/pgadmin4:${PGADMIN_IMAGE_TAG:-latest}
container_name: ${PGADMIN_CONTAINER_NAME:-pgadmin}
restart: unless-stopped
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin@example.com}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-pgadmin}
PGADMIN_LISTEN_PORT: ${PGADMIN_LISTEN_PORT:-80}
ports:
- ${PGADMIN_PORT:-15432}:80
volumes:
- ${PGADMIN_DATA_DIR:-pgadmin_data}:/var/lib/pgadmin
depends_on:
- postgres
networks:
- pg_net
pg_entrypoint/pg_entrypoint.sh
pg_entrypoint.sh | |
---|---|