PostgreSQL and pgAdmin in Docker Compose: Quickstart

Andrés

8 July 2023

PostgreSQL and pgAdmin in Docker Compose: Quickstart Discover how to get PostgreSQL and pgAdmin up and running in an agile way with Docker Compose. A quick guide to get your tools ready in minutes in your local development environment.

Translated with www.DeepL.com/Translator

The PostgreSQL database is an open source object-relational database system. PostgreSQL has a graphical user interface (GUI) administration control for database administration called pgAdmin. pgAdmin is a design and management interface for the PostgreSQL database. Simple operations, datasheets and databases can be performed with pgAdmin by interacting with the local file system of the database allowed by the user.

Docker will be the tool that will help us to run these two services easily and quickly, with data persistence. This way we will have an environment ready in a few minutes to continue working.

Docker compose up: PostgreSQL y pgAdmin

Requires docker installed

Create a folder in your project directory and inside it a docker-compose.yml file with the following content:

version: '3.8'
services:
  db:
    container_name: pg_container
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: admin
      POSTGRES_DB: my_db
      PGDATA: /var/lib/postgresql/data
    ports:
      - 5432:5432
    volumes:
      - pgdata:/var/lib/postgresql/data
  pgadmin:
    container_name: pgadmin4_container
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: admin
    ports:
      - "5050:80"
    volumes:
      - pgadmin-data:/var/lib/pgadmin

volumes:
  pgdata:
  pgadmin-data:

  • Link to the full documentation of the image used for PostgreSQL.
  • Link to the full documentation of the image used for pgAdmin.

Save the changes and then raise the containers with the following command:

docker compose up

If you want to leave the containers running in the background don’t forget the -d flag. You will be able to access pgAdmin in your browser at http://localhost:5050.

main view of pgAdmin

And that’s it. Important: You can use whatever credentials you want as long as it is a local development environment and do not pretend to use this definition of docker compose in a productive environment.

¡Hola a todos! 👋 ¿Disfrutaron leyendo el artículo? ¡Me encantaría conocer sus opiniones! 💬 No duden en dejar un comentario abajo, ya sea para compartir sus comentarios, preguntas o simplemente saludar. ¡No es necesario registrarse, solo compartan algo valioso! 😊
Hey there! 👋 Enjoyed reading the post? I'd love to hear your thoughts! 💬 Feel free to drop a comment below—whether it's feedback, questions, or just saying hi. No need to sign up, just share something valuable! 😊
Carbon impact of this web page
👷 Contratame / Hire me 👷