Databases 11 min read

Deploy PostgreSQL on AlmaLinux with Docker Compose in One Click

This guide walks you through installing Docker and Docker Compose on AlmaLinux, creating a concise docker‑compose.yml to run PostgreSQL in an isolated container, connecting with DataGrip, and managing the lifecycle of the database service with simple commands.

IT Xianyu
IT Xianyu
IT Xianyu
Deploy PostgreSQL on AlmaLinux with Docker Compose in One Click

Learn how to run a PostgreSQL database on an AlmaLinux host using Docker Compose, from installation to connection and cleanup.

Why Docker Compose?

One‑click deploy & destroy – a single command starts or removes the whole stack.

Environment isolation – PostgreSQL runs inside a container, keeping the host clean.

Configuration as code – all settings live in docker-compose.yml, easy to version.

Clear relationships – the YAML defines service, port mapping, and volume mapping, which Docker Engine uses to create and manage the container.

Prerequisites

Update the system: sudo dnf update -y Install Docker:

sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io -y
sudo systemctl start docker
sudo systemctl enable docker

Install Docker Compose:

# Replace VERSION with the latest release, e.g. v2.27.0
sudo curl -L "https://github.com/docker/compose/releases/download/VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

Create the database definition (docker-compose.yml)

In a convenient directory (e.g. ~/postgres-demo) create the file with the following content:

version: '3.8'
services:
  postgres:
    image: postgres:latest
    container_name: pg-container
    environment:
      - POSTGRES_USER=postgresuser
      - POSTGRES_PASSWORD=YourStrongPassw0rd!
      - POSTGRES_DB=postgresdb
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgresuser -d postgresdb"]
      interval: 10s
      timeout: 5s
      retries: 5

Start the service

docker-compose up -d

This pulls the PostgreSQL image (if not cached) and launches the container in detached mode.

Verify the container

docker-compose ps

You should see the container listed with State Up (healthy) if the health check is configured.

Connect with DataGrip

Open DataGrip and add a new PostgreSQL data source.

Set Host to the AlmaLinux IP (or localhost for local testing).

Set Port to the host side of the mapping (default 5432).

Enter User postgresuser, Password YourStrongPassw0rd!, and Database postgresdb.

Test the connection; a successful test confirms the setup.

Stop and clean up

To stop the container while keeping data:

cd ~/postgres-demo
docker-compose down

To remove the container and any anonymous volumes (the named pgdata directory is preserved): docker-compose down -v Delete ~/postgres-demo/pgdata manually if you really want to erase the database files.

By following these steps you have a reproducible, isolated PostgreSQL instance managed by Docker Compose, ready for development or testing, and easily reachable from GUI tools like DataGrip.

containerizationPostgreSQLDocker ComposeDatabase DeploymentAlmaLinuxDataGrip
IT Xianyu
Written by

IT Xianyu

We share common IT technologies (Java, Web, SQL, etc.) and practical applications of emerging software development techniques. New articles are posted daily. Follow IT Xianyu to stay ahead in tech. The IT Xianyu series is being regularly updated.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.