๐ณ Docker Installation on AlmaLinux: Complete Container Guide
Ready to dive into the world of containers? ๐ Today weโll install Docker on AlmaLinux and unlock the power of containerization! Whether youโre a developer wanting to package applications or a DevOps engineer building scalable infrastructure, this guide makes Docker simple and accessible for everyone! ๐ฏ
๐ค Why is Docker on AlmaLinux Important?
Docker on AlmaLinux delivers amazing benefits:
- ๐ Application portability - Run anywhere with consistent environments
- ๐ง Resource efficiency - Use hardware more effectively than traditional VMs
- ๐ Development speed - Build, test, and deploy applications faster
- ๐ Environment isolation - Keep applications separate and secure
- โญ Microservices ready - Perfect foundation for modern architectures
๐ฏ What You Need
Before starting your Docker journey:
- โ AlmaLinux 9 system (64-bit required)
- โ Root or sudo access
- โ At least 2GB RAM (4GB recommended)
- โ Internet connection for downloading images
- โ Basic command line knowledge (weโll guide you!)
๐ Step 1: Prepare AlmaLinux for Docker
Letโs get your system ready for Docker! ๐ ๏ธ
Update System and Install Prerequisites
# Update your AlmaLinux system
sudo dnf update -y
# Install required packages
sudo dnf install -y yum-utils device-mapper-persistent-data lvm2
# Install additional useful tools
sudo dnf install -y curl wget git nano
# Check system architecture (should be x86_64)
uname -m
# Verify kernel version (should be 3.10 or higher)
uname -r
echo "โ
System prepared for Docker installation!"
Remove Old Docker Versions (if any)
# Remove any old Docker installations
sudo dnf remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# Clean up old configuration
sudo rm -rf /var/lib/docker/
sudo rm -rf /etc/docker/
echo "โ
Old Docker versions removed!"
Pro tip: ๐ก Itโs normal if some packages arenโt found - that just means they werenโt installed before!
๐ง Step 2: Install Docker Engine
Now letโs install the latest Docker Engine:
Add Docker Repository
# Add Docker's official repository
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
# Verify repository was added
dnf repolist | grep docker
# Update package index
sudo dnf update -y
echo "โ
Docker repository added successfully!"
Install Docker Engine and Tools
# Install Docker CE (Community Edition)
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Verify Docker is installed
docker --version
# Check installed components
rpm -qa | grep docker
# Verify containerd is installed
containerd --version
echo "โ
Docker Engine installed successfully!"
Start and Enable Docker Service
# Start Docker service
sudo systemctl start docker
# Enable Docker to start at boot
sudo systemctl enable docker
# Check Docker service status
sudo systemctl status docker
# Verify Docker daemon is running
sudo docker info
echo "โ
Docker service is running!"
Whatโs happening: ๐
- Docker CE (Community Edition) is the free version of Docker
- containerd is the container runtime that Docker uses
- docker-buildx enables advanced build features
- docker-compose-plugin lets you manage multi-container applications
๐ Step 3: Configure Docker for Regular Users
Let Docker work without sudo:
Add User to Docker Group
# Create docker group (usually created automatically)
sudo groupadd docker
# Add your user to docker group
sudo usermod -aG docker $USER
# Check group membership
groups $USER
# Apply group changes (logout/login or use newgrp)
newgrp docker
# Test Docker without sudo
docker run hello-world
echo "โ
Docker configured for regular user access!"
Configure Docker Daemon
# Create Docker daemon configuration
sudo mkdir -p /etc/docker
# Configure Docker daemon settings
sudo tee /etc/docker/daemon.json << 'EOF'
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
],
"live-restore": true,
"default-runtime": "runc"
}
EOF
# Restart Docker to apply configuration
sudo systemctl restart docker
# Verify configuration
sudo docker info | grep -A 10 "Server:"
echo "โ
Docker daemon configured!"
โ Step 4: Test and Verify Docker Installation
Letโs make sure everything works perfectly:
Basic Docker Tests
# Test 1: Run hello-world container
docker run hello-world
# Test 2: Check Docker version
docker version
# Test 3: Display system information
docker info
# Test 4: List Docker images
docker images
# Test 5: List running containers
docker ps
echo "โ
All basic tests passed!"
Container Management Tests
# Run an interactive container
docker run -it --name test-container alpine sh
# Inside the container, try some commands:
# ls -la
# echo "Hello from container!"
# exit
# List all containers (including stopped)
docker ps -a
# Remove the test container
docker rm test-container
# Download and run nginx web server
docker run -d --name web-server -p 8080:80 nginx
# Check if nginx is running
curl http://localhost:8080
# View container logs
docker logs web-server
# Stop and remove nginx container
docker stop web-server
docker rm web-server
echo "โ
Container management tests completed!"
๐ฎ Quick Examples
Example 1: Development Environment Setup ๐ป
# Create a development workspace
mkdir ~/docker-projects && cd ~/docker-projects
# Run a Node.js development container
docker run -it --name nodejs-dev \
-v $(pwd):/workspace \
-p 3000:3000 \
-w /workspace \
node:18-alpine sh
# Inside the container, create a simple app:
echo 'console.log("Hello from Docker!");' > app.js
node app.js
exit
# Run the app from host
docker start nodejs-dev
docker exec nodejs-dev node app.js
# Clean up
docker stop nodejs-dev && docker rm nodejs-dev
echo "โ
Development environment ready!"
Example 2: Database Server with Persistent Storage ๐๏ธ
# Create data directory
mkdir -p ~/docker-data/mysql
# Run MySQL container with persistent storage
docker run -d \
--name mysql-server \
-e MYSQL_ROOT_PASSWORD=SecurePassword123! \
-e MYSQL_DATABASE=testdb \
-e MYSQL_USER=testuser \
-e MYSQL_PASSWORD=TestPass123! \
-v ~/docker-data/mysql:/var/lib/mysql \
-p 3306:3306 \
mysql:8.0
# Wait for MySQL to start (about 30 seconds)
sleep 30
# Test database connection
docker exec -it mysql-server mysql -u root -pSecurePassword123! -e "SHOW DATABASES;"
# Connect to the test database
docker exec -it mysql-server mysql -u testuser -pTestPass123! testdb -e "CREATE TABLE users (id INT, name VARCHAR(50)); INSERT INTO users VALUES (1, 'Docker User'); SELECT * FROM users;"
# View container resource usage
docker stats mysql-server --no-stream
# Stop MySQL (data persists in ~/docker-data/mysql)
docker stop mysql-server
echo "โ
Database server with persistent storage working!"
Example 3: Web Application Stack ๐
# Create a simple web application stack
mkdir -p ~/web-app && cd ~/web-app
# Create a simple HTML file
cat > index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
<title>My Docker App</title>
<style>
body { font-family: Arial; text-align: center; padding: 50px; }
.container { background: #f4f4f4; padding: 20px; border-radius: 10px; }
</style>
</head>
<body>
<div class="container">
<h1>๐ณ Welcome to My Docker App!</h1>
<p>This is running on AlmaLinux with Docker!</p>
<p>Container ID: <span id="hostname"></span></p>
</div>
<script>
document.getElementById('hostname').textContent = window.location.hostname;
</script>
</body>
</html>
EOF
# Run nginx with custom content
docker run -d \
--name my-web-app \
-p 8080:80 \
-v $(pwd):/usr/share/nginx/html:ro \
nginx:alpine
# Test the web application
curl -s http://localhost:8080 | grep "Welcome to My Docker App"
# View in browser: http://your-server-ip:8080
# Monitor container performance
docker stats my-web-app --no-stream
# View access logs
docker logs my-web-app
echo "โ
Web application stack deployed!"
echo "Visit: http://localhost:8080"
๐จ Fix Common Problems
Problem 1: Permission Denied When Running Docker โ
Symptoms:
- โGot permission denied while trying to connect to the Docker daemonโ
- Docker commands require sudo
Try this:
# Check if you're in docker group
groups $USER | grep docker
# If not in group, add yourself
sudo usermod -aG docker $USER
# Apply group changes
newgrp docker
# Or logout and login again
# After logout/login, test:
docker run hello-world
Problem 2: Docker Service Wonโt Start โ
Try this:
# Check Docker service status
sudo systemctl status docker
# Check Docker daemon logs
sudo journalctl -u docker -f
# Try starting Docker manually
sudo systemctl start docker
# If still failing, check system resources
df -h
free -h
# Restart Docker completely
sudo systemctl restart docker
Problem 3: Cannot Pull or Run Containers โ
Check these things:
# Test internet connectivity
ping -c 3 docker.io
# Check DNS resolution
nslookup docker.io
# Test Docker Hub connection
docker pull alpine:latest
# Check firewall settings
sudo firewall-cmd --list-all
# If behind corporate firewall, configure proxy:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf << 'EOF'
[Service]
Environment="HTTP_PROXY=http://proxy.company.com:8080"
Environment="HTTPS_PROXY=http://proxy.company.com:8080"
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
๐ Simple Commands Summary
Task | Command |
---|---|
๐ Check Docker version | docker --version |
๐ง Run container | docker run image-name |
๐ List running containers | docker ps |
๐ Stop container | docker stop container-name |
โป๏ธ Remove container | docker rm container-name |
๐ List images | docker images |
โ Remove image | docker rmi image-name |
๐ก Tips for Success
- Start simple ๐ - Begin with basic containers before complex applications
- Use official images ๐ - Always prefer official Docker Hub images
- Manage resources ๐ - Monitor container CPU and memory usage
- Version control ๐ - Tag your custom images with meaningful versions
- Security first ๐ - Keep Docker and container images updated
๐ What You Learned
Congratulations! Now you can:
- โ Install Docker Engine on AlmaLinux from official repositories
- โ Configure Docker for secure, rootless operation
- โ Run, manage, and troubleshoot containers effectively
- โ Create development environments and web application stacks
- โ Implement persistent storage and container networking
๐ฏ Why This Matters
Your Docker setup on AlmaLinux provides:
- ๐ Modern development workflow with containerized applications
- ๐ Production-ready platform for deploying microservices
- ๐ Consistent environments across development, testing, and production
- โก Resource efficiency compared to traditional virtual machines
Remember: Docker is not just a tool - itโs a complete paradigm shift that enables you to build, ship, and run applications anywhere with confidence! โญ
Youโve successfully mastered Docker installation on AlmaLinux! You now have the foundation for modern containerized applications, microservices architectures, and cloud-native development! ๐