I'm trying to create a PostgreSQL database using Docker — with Docker Desktop on my own machine.
First, let’s create a folder for the setup:
mkdir posgresql-db
cd posgresql-db
touch docker-compose.yml
Now, open the docker-compose.yml
file and add the following service configuration:
version: '6.3'
services:
db:
image: postgres:16
container_name: postgres_db
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: admin
POSTGRES_DB: postgres
ports:
- "5433:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
That’s it for now! You can run it with:
docker-compose up --build