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

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

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!

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup 🚀

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay