Postgres in Docker
permanent
Easy to run Postgres in Docker - summarized from How to Run PostgreSQL and pgAdmin Using Docker by Mahbub Zaman Towards Data Science
Use the following Docker Compose
version: '3.8'
services:
db:
container_name: pg_container
image: postgres
restart: always
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: test_db
ports:
- "5432:5432"
pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "5050:80"
Store it in a folder, and just run docker compose up
from that folder.
Then, when both the services are up and running…
- Open up pgAdmin in a browser at
localhost:5050
- Log in to pgAdmin using the username and password mentioned above
- To connect to Postgres from pgAdmin, use the host
pg_container
(the name of the container that we defined in the Docker Compose file) -- The network works that way
- List the docker containers with
docker ps
, and grab the container id for thepostgres
container. - Get the IP address of the
postgres
container usingdocker inspect <id> | grep IPAddress
- Take the IP Address and use it to create connection from pgAdmin
Last update :
16 octobre 2023
Created : 21 septembre 2023
Created : 21 septembre 2023