Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save christianjjc/74ea07e33789b0f256188182d2504c82 to your computer and use it in GitHub Desktop.
Save christianjjc/74ea07e33789b0f256188182d2504c82 to your computer and use it in GitHub Desktop.
Script to create a containers wiht PostgreSQL database and client with PgAdmin - All inside Docker
version: '4'
services:
dberp:
container_name: ra_postgres_db
image: postgres:15-alpine3.19
volumes:
#- postgres-db:/var/lib/postgresql/data #example
- ./postgres:/var/lib/postgresql/data
ports:
- '5432:5432'
networks:
- backend
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_DB=${DB_NAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
pgAdmin:
depends_on:
- dberp
container_name: ra_pgadmin
image: dpage/pgadmin4:8.0
volumes:
#- pgadmin:/var/lib/pgadmin #example
- ./pgadmin:/var/lib/pgadmin
ports:
- '8080:80'
networks:
- backend
environment:
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PASSWORD}
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_EMAIL}
networks:
backend:
name: backend_bd
driver: bridge
# to execute query --> docker compose up -d (on your terminal inside the directory)
# to enter pgadmin --> http://localhost:8080
# this file needs .env file below.
##################################################
# DB_USER=whatever_db_username
# DB_NAME=whatever_db_name
# DB_PASSWORD=whatever_db_password
# PGADMIN_PASSWORD=whatever_pggadmin_username
# PGADMIN_EMAIL=aaa@email.com
#to connect --> replace values in this string
# DATABASE_URL="postgresql://{db_user}:{db_password}@localhost:5432/{db_name}?schema=public"
##################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment