DEV Community

abbazs
abbazs

Posted on

4 3 1

How to setup a postgres and pgadmin to be used at development and testing of a application using docker-compose?

Using docker compose we can achieve this. In the following docker-compose code we are binding the local folder to the folder in the docker for data persistence.

Copy the code to a file named docker-compose.yml and run the command docker-compose -f docker-compose.yml up

version: "3.5"

services:
  postgres:
    container_name: postgres_container
    image: postgres
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
      POSTGRES_DB: ${POSTGRES_DB}
      PGDATA: /data/postgres
    volumes:
      - ./db_data:/data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped

  pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
      PGADMIN_CONFIG_SERVER_MODE: "False"
    volumes:
      # The local folder owner and group must be set to 5050
      # for the volume to work. Otherwise pgadmin is not able to
      # write to the local folder
      # sudo chown -R 5050:5050 pgadmin_data
      - ./pgadmin_data:/var/lib/pgadmin
    ports:
      - "${PGADMIN_PORT:-5050}:80"
    networks:
      - postgres
    restart: unless-stopped

networks:
  postgres:
    driver: bridge
Enter fullscreen mode Exit fullscreen mode

Billboard image

Synthetic monitoring. Built for developers.

Join Vercel, Render, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (1)

Collapse
 
gugaguichard profile image
Gustavo (Guga) Guichard

Hey Abbaz, great guide! If you're looking for a more streamlined way to manage PostgreSQL databases, check out Flashboard. I’m one of the creators, and it offers a web-based UI that simplifies PostgreSQL management without additional setup like Docker. Would love to hear your thoughts!

Billboard image

Use Playwright to test. Use Playwright to monitor.

Join Vercel, CrowdStrike, and thousands of other teams that run end-to-end monitors on Checkly's programmable monitoring platform.

Get started now!

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay