Neste post, vamos configurar o docker-compose, para disponibilizar o PostgreSQL com PgAdmin, de maneira fácil e rápida.
Premissa: Espera-se que tenha instalado o Docker e Docker-Compose.
docker-compose.yml
version: '3'
services:
teste-postgres-compose:
image: postgres
environment:
POSTGRES_PASSWORD: "Postgres2021!"
ports:
- "15432:5432"
volumes:
- /home/fernando/data/postgres:/var/lib/postgresql/data
networks:
- postgres-compose-network
teste-pgadmin-compose:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: "lfchaim@gmail.com"
PGADMIN_DEFAULT_PASSWORD: "PgAdmin2021!"
ports:
- "16543:80"
depends_on:
- teste-postgres-compose
networks:
- postgres-compose-network
networks:
postgres-compose-network:
driver: bridge
Subindo os conteiners
$ sudo docker-compose up -d
Ao final do processo, deve aparecer o log final
Status: Downloaded newer image for dpage/pgadmin4:latest
Creating postgres_teste-postgres-compose_1 ... done
Creating postgres_teste-pgadmin-compose_1 ... done
Pode-se verificar os conteiners rodando, com o comando
$ sudo docker ps
Deverá aparecer
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fffaaa4887c dpage/pgadmin4 "/entrypoint.sh" About a minute ago Up About a minute 443/tcp, 0.0.0.0:16543->80/tcp postgres_teste-pgadmin-compose_1
63e1934f7cdb postgres "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:15432->5432/tcp postgres_teste-postgres-compose_1
Agora, vamos acessar o PgAdmin
Abra um navegador e digite: http://localhost:16543
Forneça o usuário e senha informados no docker-compose
Exemplo: lfchaim@gmail.com / PgAdmin2021!
Na tela do PgAdmin, clique em “Add New Server”
Dê um nome: teste-postgres-compose
Repita o nome em Host: teste-postgres-compose
Usuário: postgres
Senha: Postgres2021! (mesma do docker-compose)
Clicar em “Save”
Pronto! Seu ambiente está criado!