Explore how to use the PostgreSQL on a Docker Container
🚨🚧 THIS IS A TESTING REPOSITORY TO BE USED LOCALLY ONLY 🚧🚨
1. Pull the PostgreSQL Docker Image
docker pull postgres:17-alpine2. Run a PostgreSQL Container
docker run -d \
--name test-postgres-container \
-e POSTGRES_USER=admin \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=test \
-p 5432:5432 \
postgres:17-alpinewith Volume
docker run -d \
--name test-postgres-container \
-e POSTGRES_USER=admin \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=test \
-p 5432:5432 \
-v test_pgdata:/var/lib/postgresql/data \
postgres:17-alpinecheck the Docker volumes ( doc ref )
docker volume lscheck the disk used by Docker ( doc ref )
docker system df3. Connect to PostgreSQL
docker exec -it test-postgres-container psql -U admin -d testTest query
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL
);
INSERT INTO users (name, email) VALUES ('John Snow', 'john@snow.got');
SELECT * FROM users;4. Stop Container
docker stop test-postgres-container5. Remove Container
docker rm -f test-postgres-container1. run on background
docker compose up -d2. stop
docker compose downDefined by pgadmin_entrypoint.sh and set as executable file ( chmod +x pgadmin_entrypoint.sh )
-
pgAdmin - The Most Popular PostgreSQL Admin Tool
-
-
Install Docker Engine on Ubuntu | Docker Docs
sudo apt install \ docker-ce docker-ce-cli \ containerd.io \ docker-buildx-plugin \ docker-compose-plugin
-
Docker Compose Cheatsheet — Most useful commands with examples | by Rost Glukhov - Medium
-
-
PostgreSQL in Docker: A Step-by-Step Guide for Beginners | DataCamp
-
Dump & Restore PostgreSQL database in a Docker | Peter's Notes
-
Visualizing your PostgreSQL databases with pgAdmin | Docker Docs
-
How to create a docker-compose setup with PostgreSQL and pgAdmin4 | Hands On Programming
-
[GitHub] matschik/docker-compose-postgres-pgadmin - A Docker Compose setup for PostgreSQL and pgAdmin, ideal for development and testing environments.