?? Docker, PostgreSQL, and pgAdmin working together ?????????

?? Docker, PostgreSQL, and pgAdmin working together ????????

It's a common doubt for developers when they want to work with Docker, PostgreSQL, and pgAdmin: How do I started it? I remember seen a docker-compose.yaml somewhere...

So use this article as reference and keep it in your bookmarks to use it whenever you need ??

Here's a basic docker-compose.yml setup for a PostgreSQL database with pgAdmin. This setup will spin up two services: one for PostgreSQL and another for pgAdmin, allowing you to manage the database through a web interface.

services:
  postgres:
    image: postgres:latest
    container_name: postgres_db
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]  # Set your admin email
      PGADMIN_DEFAULT_PASSWORD: admin  # Set your pgAdmin password
    ports:
      - "8080:80"
    depends_on:
      - postgres
    volumes:
      - pgadmin_data:/var/lib/pgadmin

volumes:
  postgres_data:
  pgadmin_data:        

Explanation

  • postgres service:

Uses the postgres:latest image.

Defines environment variables for the database user, password, and default database.

Maps port 5432 on the host to 5432 in the container.

  • pgadmin service:

Uses the dpage/pgadmin4 image.

Sets environment variables for the pgAdmin default email and password.

Maps port 8080 on the host to 80 in the container (pgAdmin's default port).

  • volumes:

postgres_data: Used to persist PostgreSQL data on the host.

pgadmin_data: Used to persist pgAdmin data on the host.


Usage

  1. Save this file as docker-compose.yml.
  2. Run docker-compose up -d to start the services.
  3. Access pgAdmin at https://localhost:8080.
  4. In pgAdmin, add a new server and connect using:

Host: postgres_db

Port: 5432

Username: your_username

Password: your_password


Feel free to reach me out for questions! See you in the comments ??

Carlos Eduardo Junior

Java Backend Developer | Spring Certified Professional | Spring Boot | AWS | ReactJS | Fullstack Software Engineer

4 个月

Very informative

Otávio Prado

Senior Business Analyst | ITIL | Communication | Problem-Solving | Critical Thinking | Data Analysis and Visualization | Documentation | BPM | Time Management | Agile | Jira | Requirements Gathering | Scrum

4 个月

Interesting! Thanks for sharing Rodrigo Tenório ! ????

Eduardo Diogo

Senior Fullstack Engineer | Front-End focused developer | React | Next.js | Vue | Typescript | Node | Laravel | .NET | Azure | AWS

4 个月

Thanks for this clear explanation of Docker Compose setup for PostgreSQL and pgAdmin! Great step-by-step guide for easy database management. Appreciate the helpful usage instructions.

Marcus Vinicius Bueno Nunes

Data Scientist Specialist | Machine Learning | LLM | GenAI | NLP | AI Engineer

4 个月

Setting up PostgreSQL with pgAdmin in Docker has never been easier—this guide is a lifesaver for quick and efficient database management!

要查看或添加评论,请登录

Rodrigo Tenório的更多文章

社区洞察

其他会员也浏览了