Ratul was here

Deploying PostgreSQL and pgAdmin using Docker Compose

Docker is a popular tool used by developers to create and deploy applications in containers. Docker Compose is a tool used for defining and running multi-container Docker applications. In this blog post, we will describe a Docker Compose file that deploys a PostgreSQL database and a pgAdmin dashboard.

The Docker Compose File

The Docker Compose file has two services defined - postgres and pgadmin. The postgres service is based on the official PostgreSQL Docker image and runs a PostgreSQL server inside a container. The pgadmin service is based on the official pgAdmin4 Docker image and runs a pgAdmin dashboard inside a container.

services:
  postgres:
    container_name: postgres
    image: postgres:alpine
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PW}
      - POSTGRES_DB=${POSTGRES_DB} #optional (specify default database instead of $POSTGRES_DB)
      - PGDATA=/data/postgres
    volumes:
      - ${PWD}/data:/data/postgres
    ports:
      - "5432:5432"
    restart: always

  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4:latest
    environment:
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_MAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PW}
    ports:
      - "5050:80"
    restart: always

Advantages and Disadvantages

Using Docker Compose to deploy PostgreSQL and pgAdmin has several advantages, including:

However, using Docker Compose to deploy PostgreSQL and pgAdmin also has some disadvantages, including:

This is mostly for my own use. Please suggest improvements in it if you can.

#docker #local_development #pgAdmin #postgresql