scheme
mongo
+
+
โˆซ
+
tf
k8s
+
arch
redhat
webpack
android
+
0x
+
+
swc
influxdb
vscode
mysql
++
weaviate
node
+
//
linux
+
websocket
+
+
ocaml
azure
==
+
+
+
bsd
+
+
mint
grafana
+
+
vault
bash
express
apex
+
+
+
phoenix
xcode
express
vscode
solid
+
+
โˆซ
+
https
+
webstorm
+
+
+
+
rb
โˆ‘
โˆซ
โˆž
+
+
@
packer
โ‰ 
html
+
vb
+
prettier
+
+
rails
+
+
+
+
+
+
Back to Blog
๐Ÿณ AlmaLinux Docker Container Setup: Complete Containerization Guide
AlmaLinux Docker Containers

๐Ÿณ AlmaLinux Docker Container Setup: Complete Containerization Guide

Published Sep 17, 2025

Master Docker containers on AlmaLinux! Learn Docker installation, container management, images, networking, and orchestration. Complete beginner-friendly guide with real examples.

38 min read
0 views
Table of Contents

๐Ÿณ AlmaLinux Docker Container Setup: Complete Containerization Guide

Welcome to the revolutionary world of Docker containers on AlmaLinux! ๐ŸŽ‰ Think of containers as magical boxes that can run any application anywhere - theyโ€™re like having a portable, self-contained universe for your software! Whether youโ€™re deploying web applications, setting up development environments, or building microservices, Docker containers will transform how you work with software! ๐Ÿ“ฆ

Docker might seem complex at first, but itโ€™s actually incredibly intuitive and powerful! ๐Ÿ’ช From running your first container to orchestrating complex multi-service applications, weโ€™ll learn everything step by step. Get ready to become a containerization expert and join the cloud-native revolution! โœจ

๐Ÿค” Why are Docker Containers Important?

Docker containers are game-changers for modern software deployment! Hereโ€™s why you should master them:

  • ๐Ÿš€ Consistent Environments: Run the same software everywhere - development, testing, production
  • โšก Fast Deployment: Start applications in seconds instead of minutes
  • ๐Ÿ’พ Efficient Resource Usage: Multiple containers share the same OS kernel
  • ๐Ÿ”ง Easy Scaling: Scale applications up or down instantly
  • ๐Ÿ“ฆ Application Packaging: Bundle applications with all their dependencies
  • ๐ŸŒ Microservices Ready: Perfect for building modern distributed applications
  • ๐Ÿ”„ Version Control: Treat infrastructure as code with versioned container images
  • ๐Ÿ›ก๏ธ Isolation: Keep applications separate and secure from each other

๐ŸŽฏ What You Need

Before we start working with Docker, make sure you have:

โœ… AlmaLinux 8 or 9 installed and running โœ… Root or sudo access to install and configure Docker โœ… Internet connection for downloading container images โœ… Basic command line knowledge (cd, ls, cat commands) โœ… Understanding of basic networking (ports, IP addresses) โœ… At least 2GB RAM for running multiple containers โœ… Some applications you want to containerize (optional but helpful)

๐Ÿ“ Understanding Docker Concepts

Letโ€™s start by understanding how Docker works! ๐ŸŽ“

Docker Architecture

# Check if Docker is already installed
docker --version
# Output: Shows Docker version if installed

# Check system information
uname -a
# Output: Shows kernel version (containers share host kernel)

# View system resources
free -h
df -h
# Output: Shows available memory and disk space

# Check if virtualization is enabled
grep -E '(vmx|svm)' /proc/cpuinfo
# Output: Shows CPU virtualization features

Basic Docker Concepts

# Key Docker concepts:
echo "Container: Running instance of an image"
echo "Image: Read-only template for creating containers"
echo "Dockerfile: Text file with instructions to build images"
echo "Registry: Repository for storing and sharing images"
echo "Volume: Persistent storage for containers"
echo "Network: Communication layer between containers"

# Docker workflow:
echo "1. Write Dockerfile"
echo "2. Build image from Dockerfile"
echo "3. Run container from image"
echo "4. Push image to registry (optional)"

๐Ÿ”ง Installing Docker on AlmaLinux

Docker Engine Installation

# Update system packages
sudo dnf update -y
# Output: Updates all system packages

# Install required packages
sudo dnf install -y dnf-utils device-mapper-persistent-data lvm2
# Output: Installs Docker prerequisites

# Add Docker repository
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Output: Adds official Docker repository

# Install Docker Engine
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
# Output: Installs Docker and related tools

# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Output: Starts Docker and enables it at boot

# Verify Docker installation
sudo docker run hello-world
# Output: Downloads and runs test container

Docker Post-Installation Setup

# Add user to docker group (avoid using sudo)
sudo usermod -aG docker $USER
# Output: Adds current user to docker group

# Apply group changes (logout/login or use newgrp)
newgrp docker
# Output: Applies group membership

# Test Docker without sudo
docker run hello-world
# Output: Should work without sudo

# Configure Docker daemon
sudo nano /etc/docker/daemon.json
# Add this content:
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "storage-driver": "overlay2"
}

# Restart Docker to apply configuration
sudo systemctl restart docker
# Output: Restarts Docker with new configuration

๐ŸŒŸ Working with Docker Images

Pulling and Managing Images

# Search for images on Docker Hub
docker search nginx
# Output: Shows available nginx images

# Pull an image from Docker Hub
docker pull nginx:latest
# Output: Downloads latest nginx image

# Pull specific version
docker pull ubuntu:20.04
# Output: Downloads Ubuntu 20.04 image

# List downloaded images
docker images
# Output: Shows all local Docker images

# Get detailed image information
docker inspect nginx:latest
# Output: Shows detailed image metadata

# Remove an image
docker rmi ubuntu:20.04
# Output: Removes the specified image

Building Custom Images

# Create a simple Dockerfile
mkdir ~/my-app
cd ~/my-app
nano Dockerfile

# Add this content:
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

# Create a simple HTML file
cat > index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
    <title>My App</title>
</head>
<body>
    <h1>Hello from Docker!</h1>
    <p>This is my custom web application running in a container.</p>
</body>
</html>
EOF

# Build the image
docker build -t my-web-app:v1.0 .
# Output: Builds custom image with tag

# Verify the new image
docker images | grep my-web-app
# Output: Shows your custom image

โœ… Running and Managing Containers

Basic Container Operations

# Run a container in background
docker run -d --name my-nginx -p 8080:80 nginx:latest
# Output: Starts nginx container on port 8080

# List running containers
docker ps
# Output: Shows all running containers

# List all containers (including stopped)
docker ps -a
# Output: Shows all containers

# View container logs
docker logs my-nginx
# Output: Shows container logs

# Follow container logs in real-time
docker logs -f my-nginx
# Output: Shows live log output

# Execute commands in running container
docker exec -it my-nginx /bin/bash
# Output: Opens interactive shell in container

# Stop a container
docker stop my-nginx
# Output: Gracefully stops the container

# Start a stopped container
docker start my-nginx
# Output: Starts the container again

Advanced Container Management

# Run container with environment variables
docker run -d --name web-app \
  -e DATABASE_URL=mysql://db:3306/myapp \
  -e ENV=production \
  -p 3000:3000 \
  my-web-app:v1.0
# Output: Runs container with environment variables

# Run container with volume mounting
docker run -d --name data-container \
  -v /host/data:/container/data \
  -v logs:/var/log \
  nginx:latest
# Output: Mounts host directory and named volume

# Run container with resource limits
docker run -d --name limited-app \
  --memory=512m \
  --cpus=0.5 \
  nginx:latest
# Output: Runs container with memory and CPU limits

# View container resource usage
docker stats
# Output: Shows real-time resource usage

# Inspect container details
docker inspect my-nginx
# Output: Shows detailed container information

๐Ÿ”ง Docker Networking and Volumes

Container Networking

# List Docker networks
docker network ls
# Output: Shows available networks

# Create custom network
docker network create --driver bridge my-network
# Output: Creates custom bridge network

# Run containers on custom network
docker run -d --name app1 --network my-network nginx:latest
docker run -d --name app2 --network my-network nginx:latest
# Output: Runs containers on same network

# Test container connectivity
docker exec app1 ping app2
# Output: Tests network connectivity between containers

# Inspect network details
docker network inspect my-network
# Output: Shows network configuration

# Connect running container to network
docker network connect my-network existing-container
# Output: Adds container to network

Volume Management

# Create named volume
docker volume create my-data
# Output: Creates persistent volume

# List volumes
docker volume ls
# Output: Shows all Docker volumes

# Run container with named volume
docker run -d --name db-container \
  -v my-data:/var/lib/mysql \
  mysql:8.0
# Output: Runs MySQL with persistent storage

# Backup volume data
docker run --rm \
  -v my-data:/source \
  -v $(pwd):/backup \
  ubuntu tar czf /backup/my-data-backup.tar.gz -C /source .
# Output: Creates backup of volume data

# Restore volume data
docker run --rm \
  -v my-data:/target \
  -v $(pwd):/backup \
  ubuntu tar xzf /backup/my-data-backup.tar.gz -C /target
# Output: Restores data to volume

# Remove unused volumes
docker volume prune
# Output: Removes unused volumes

๐ŸŽฎ Quick Examples

Example 1: Complete Web Application Stack

# Create application directory
mkdir ~/web-stack
cd ~/web-stack

# Create Docker Compose file
cat > docker-compose.yml << 'EOF'
version: '3.8'

services:
  web:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./html:/usr/share/nginx/html
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - app
    networks:
      - frontend

  app:
    build: .
    environment:
      - DATABASE_URL=mysql://db:3306/webapp
      - REDIS_URL=redis://cache:6379
    depends_on:
      - db
      - cache
    networks:
      - frontend
      - backend

  db:
    image: mysql:8.0
    environment:
      - MYSQL_ROOT_PASSWORD=rootpassword
      - MYSQL_DATABASE=webapp
      - MYSQL_USER=appuser
      - MYSQL_PASSWORD=apppassword
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - backend

  cache:
    image: redis:alpine
    volumes:
      - cache_data:/data
    networks:
      - backend

volumes:
  db_data:
  cache_data:

networks:
  frontend:
  backend:
EOF

# Create application Dockerfile
cat > Dockerfile << 'EOF'
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
EOF

# Create simple web content
mkdir html
cat > html/index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
    <title>Web Stack Demo</title>
</head>
<body>
    <h1>Web Application Stack</h1>
    <p>Running on Docker containers!</p>
    <ul>
        <li>Nginx (Web Server)</li>
        <li>Node.js (Application)</li>
        <li>MySQL (Database)</li>
        <li>Redis (Cache)</li>
    </ul>
</body>
</html>
EOF

# Start the entire stack
docker-compose up -d
# Output: Starts all services

# Check running services
docker-compose ps
# Output: Shows status of all services

# View logs from all services
docker-compose logs
# Output: Shows logs from all containers

# Scale application service
docker-compose up -d --scale app=3
# Output: Runs 3 instances of the app service

Example 2: Development Environment

# Create development environment
mkdir ~/dev-env
cd ~/dev-env

# Create development Docker Compose
cat > docker-compose.dev.yml << 'EOF'
version: '3.8'

services:
  dev-workspace:
    image: ubuntu:20.04
    tty: true
    stdin_open: true
    working_dir: /workspace
    volumes:
      - .:/workspace
      - dev_home:/home/developer
    environment:
      - USER=developer
    command: bash -c "
      apt-get update &&
      apt-get install -y git nodejs npm python3 python3-pip vim curl &&
      useradd -m developer &&
      chown -R developer:developer /workspace &&
      su - developer"

  database:
    image: postgres:13
    environment:
      - POSTGRES_DB=devdb
      - POSTGRES_USER=developer
      - POSTGRES_PASSWORD=devpass
    ports:
      - "5432:5432"
    volumes:
      - db_dev_data:/var/lib/postgresql/data

  redis:
    image: redis:alpine
    ports:
      - "6379:6379"

  mailhog:
    image: mailhog/mailhog
    ports:
      - "1025:1025"  # SMTP
      - "8025:8025"  # Web UI

volumes:
  dev_home:
  db_dev_data:
EOF

# Start development environment
docker-compose -f docker-compose.dev.yml up -d
# Output: Starts development stack

# Connect to development workspace
docker-compose -f docker-compose.dev.yml exec dev-workspace bash
# Output: Opens shell in development container

# Create development scripts
cat > start-dev.sh << 'EOF'
#!/bin/bash
echo "Starting development environment..."
docker-compose -f docker-compose.dev.yml up -d
echo "Development environment running!"
echo "Database: localhost:5432"
echo "Redis: localhost:6379"
echo "Mail UI: http://localhost:8025"
EOF

chmod +x start-dev.sh
./start-dev.sh
# Output: Starts complete development environment

Example 3: Microservices Application

# Create microservices architecture
mkdir ~/microservices
cd ~/microservices

# Create API Gateway service
mkdir api-gateway
cat > api-gateway/Dockerfile << 'EOF'
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
EOF

cat > api-gateway/nginx.conf << 'EOF'
events { worker_connections 1024; }

http {
    upstream user_service {
        server user-service:3000;
    }

    upstream order_service {
        server order-service:3000;
    }

    server {
        listen 80;

        location /api/users {
            proxy_pass http://user_service;
        }

        location /api/orders {
            proxy_pass http://order_service;
        }
    }
}
EOF

# Create user service
mkdir user-service
cat > user-service/Dockerfile << 'EOF'
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
EOF

# Create microservices docker-compose
cat > docker-compose.microservices.yml << 'EOF'
version: '3.8'

services:
  api-gateway:
    build: ./api-gateway
    ports:
      - "80:80"
    depends_on:
      - user-service
      - order-service
    networks:
      - microservices

  user-service:
    build: ./user-service
    environment:
      - DB_HOST=user-db
      - DB_NAME=users
    depends_on:
      - user-db
    networks:
      - microservices
    deploy:
      replicas: 2

  order-service:
    build: ./order-service
    environment:
      - DB_HOST=order-db
      - DB_NAME=orders
    depends_on:
      - order-db
    networks:
      - microservices
    deploy:
      replicas: 2

  user-db:
    image: postgres:13
    environment:
      - POSTGRES_DB=users
      - POSTGRES_USER=userservice
      - POSTGRES_PASSWORD=userpass
    volumes:
      - user_db_data:/var/lib/postgresql/data
    networks:
      - microservices

  order-db:
    image: postgres:13
    environment:
      - POSTGRES_DB=orders
      - POSTGRES_USER=orderservice
      - POSTGRES_PASSWORD=orderpass
    volumes:
      - order_db_data:/var/lib/postgresql/data
    networks:
      - microservices

  monitoring:
    image: prom/prometheus
    ports:
      - "9090:9090"
    networks:
      - microservices

volumes:
  user_db_data:
  order_db_data:

networks:
  microservices:
    driver: bridge
EOF

# Deploy microservices
docker-compose -f docker-compose.microservices.yml up -d
# Output: Deploys complete microservices architecture

# Scale individual services
docker-compose -f docker-compose.microservices.yml up -d --scale user-service=3 --scale order-service=3
# Output: Scales services independently

๐Ÿšจ Fix Common Problems

Problem 1: Docker Service Wonโ€™t Start

Symptoms: Docker daemon fails to start or containers wonโ€™t run

Solution:

# Check Docker service status
sudo systemctl status docker
# Output: Shows Docker service status

# Check Docker daemon logs
sudo journalctl -u docker
# Output: Shows Docker daemon logs

# Restart Docker service
sudo systemctl restart docker
# Output: Restarts Docker daemon

# Check disk space (Docker needs space)
df -h /var/lib/docker
# Output: Shows Docker storage usage

# Clean up Docker system
docker system prune -a
# Output: Removes unused containers, images, networks

# Reset Docker to defaults (last resort)
sudo systemctl stop docker
sudo rm -rf /var/lib/docker
sudo systemctl start docker
# Output: Completely resets Docker

Problem 2: Container Networking Issues

Symptoms: Containers canโ€™t communicate or reach external networks

Solution:

# Check container network configuration
docker network ls
docker network inspect bridge
# Output: Shows network configuration

# Test container connectivity
docker run --rm alpine ping google.com
# Output: Tests external connectivity

# Check iptables rules (may block Docker)
sudo iptables -L
# Output: Shows firewall rules

# Restart Docker networking
sudo systemctl restart docker
# Output: Resets Docker networks

# Create custom network for isolation
docker network create --driver bridge test-network
docker run --network test-network alpine ping google.com
# Output: Tests with custom network

# Check firewall conflicts
sudo firewall-cmd --list-all
# Ensure Docker networks are allowed

Problem 3: Container Performance Issues

Symptoms: Containers running slowly or consuming too many resources

Solution:

# Monitor container resource usage
docker stats
# Output: Shows real-time resource consumption

# Check system resources
htop
# Or use: top, free -h, df -h

# Limit container resources
docker run -d --memory=512m --cpus=0.5 nginx
# Output: Runs container with resource limits

# Check container logs for errors
docker logs container-name
# Output: Shows container error messages

# Optimize Docker storage driver
sudo nano /etc/docker/daemon.json
# Add: "storage-driver": "overlay2"

# Clean up unused Docker objects
docker system prune -a --volumes
# Output: Frees up Docker storage space

# Check for resource-heavy processes in containers
docker exec container-name top
# Output: Shows processes running in container

๐Ÿ“‹ Simple Commands Summary

CommandPurposeExample
docker runRun containerdocker run -d nginx
docker psList containersdocker ps -a
docker imagesList imagesdocker images
docker buildBuild imagedocker build -t myapp .
docker logsView logsdocker logs container-name
docker execExecute in containerdocker exec -it container bash
docker-compose upStart servicesdocker-compose up -d
docker system pruneClean updocker system prune -a

๐Ÿ’ก Tips for Success

Here are proven strategies to master Docker containers! ๐ŸŒŸ

Best Practices

  • ๐Ÿ“ฆ Keep Images Small: Use alpine or minimal base images when possible
  • ๐Ÿ”’ Security First: Run containers as non-root users when possible
  • ๐Ÿ“ Document Everything: Use clear labels and comments in Dockerfiles
  • ๐Ÿ”„ Version Images: Always tag images with meaningful versions
  • ๐Ÿงน Clean Regularly: Remove unused containers, images, and volumes
  • ๐Ÿ“Š Monitor Resources: Keep track of container resource usage
  • ๐Ÿ›ก๏ธ Scan Images: Use security scanning tools for production images
  • ๐ŸŽฏ Single Purpose: Each container should do one thing well

Development Tips

  • Use multi-stage builds to reduce image size ๐Ÿ“ˆ
  • Leverage Docker Compose for local development environments ๐Ÿ”ง
  • Use .dockerignore files to exclude unnecessary files ๐Ÿ“‹
  • Cache expensive operations early in Dockerfile layers โšก
  • Use health checks to ensure container readiness ๐Ÿฅ
  • Implement proper logging strategies for debugging ๐Ÿ“Š
  • Use secrets management for sensitive data ๐Ÿ”
  • Test containers across different environments ๐Ÿงช

๐Ÿ† What You Learned

Congratulations! Youโ€™ve mastered Docker containers on AlmaLinux! ๐ŸŽ‰ Hereโ€™s what you can now do:

โœ… Install and Configure Docker: Set up Docker Engine on AlmaLinux systems โœ… Manage Images: Pull, build, and manage Docker images effectively โœ… Run Containers: Deploy and manage containerized applications โœ… Container Networking: Configure networking between containers and services โœ… Volume Management: Handle persistent data and container storage โœ… Multi-Service Applications: Use Docker Compose for complex applications โœ… Troubleshoot Issues: Diagnose and fix common Docker problems โœ… Optimize Performance: Configure containers for optimal resource usage

๐ŸŽฏ Why This Matters

Mastering Docker containers is essential for modern application deployment! ๐Ÿš€ With these skills, you can:

  • Modernize Applications: Transform traditional deployments into cloud-native architectures ๐ŸŒ
  • Improve Development Workflow: Create consistent development environments across teams ๐Ÿ‘ฅ
  • Scale Efficiently: Deploy and scale applications quickly and reliably โšก
  • Enhance Portability: Run applications anywhere Docker is supported ๐Ÿ“ฆ
  • Reduce Infrastructure Costs: Optimize resource utilization with containerization ๐Ÿ’ฐ
  • Enable DevOps: Bridge the gap between development and operations teams ๐Ÿ”—

Docker containers represent the future of application deployment and infrastructure! Whether youโ€™re deploying simple web applications or complex microservices architectures, these skills will serve you throughout your career. Remember, containers are not just a technology - theyโ€™re a mindset shift toward modern, scalable, and efficient software delivery! โญ

Excellent work on mastering Docker containers on AlmaLinux! Youโ€™re now ready to build and deploy modern, containerized applications that scale with your needs! ๐Ÿ™Œ