Integration of PostgreSQL and pgAdmin Containers with Docker Compose

To integrate PostgreSQL and pgAdmin using Docker Compose, start by creating a compose.yaml file with the following content:

services:

  postgres:

    image: postgres

    environment:

      POSTGRES_PASSWORD: password


  pgadmin:

    image: dpage/pgadmin4

    environment:

      PGADMIN_DEFAULT_EMAIL: pg@ad.min

      PGADMIN_DEFAULT_PASSWORD: password

    ports:

      - "12345:80"

Save the code above into a file named compose.yaml on your computer. Then, open your terminal, navigate to the directory containing the file, and run the command docker compose up. Wait for Docker to create and start the containers.

Once the containers are running, open your browser and go to http://localhost:12345. You will be prompted to log in to pgAdmin. In the "Email Address / Username" field, enter pg@ad.min as specified in the compose.yaml file, and in the "Password" field, enter password. Click "Login" to access the pgAdmin dashboard.

After logging in, go to the "Register Server" screen, following the steps shown in the image below.

The "Name" field in the "General" section is required, but you can choose any name. In this case, we will choose the name db.
In the "Connection" section, fill in the "Host name/address" field with postgres (this is the DNS name automatically created when the compose is started. Docker directs it to the correct IP address, commonly 172.18.0.2, for example). The "Username" field should be set to postgres, and the "Password" field should contain the text password.

Click "Save".

Comentários

Postagens mais visitadas deste blog

Safely Refactoring Endpoints with Postman Tests

Views and Functions in PostgreSQL