+
elasticsearch
+
+
+
mint
hapi
arch
+
+
elasticsearch
istio
+
*
+
+
+
toml
vault
+
smtp
s3
vb
+
+
+
+
+
+
+
=
+
laravel
meteor
+
+
+
prettier
&
+
+
gulp
+
http
+
choo
weaviate
+
+
+
+
+
vb
+
ubuntu
phpstorm
+
hapi
+
wsl
+
+
+
gradle
clickhouse
+
+
+
π
+
+
+
+
+
npm
junit
html
bash
+
+
+
ada
windows
ionic
asm
+
bbedit
+
Back to Blog
Installing Docker on Alpine Linux 🐳
alpine-linux docker containers

Installing Docker on Alpine Linux 🐳

Published May 25, 2025

Complete guide to installing and configuring Docker on Alpine Linux. Learn container management, Docker Compose setup, and best practices for containerized applications.

10 min read
0 views
Table of Contents

Installing Docker on Alpine Linux

Docker revolutionizes application deployment through containerization. Alpine Linux’s minimal footprint makes it an excellent host for Docker containers. Let’s set up Docker on Alpine Linux! 🚀

Why Docker on Alpine Linux?

  • Minimal overhead: Alpine’s small size leaves more resources for containers
  • Security focused: Both Docker and Alpine prioritize security
  • Fast boot times: Quick container startup
  • Perfect for edge computing: Ideal for resource-constrained environments

Prerequisites

Before installing Docker:

  • Alpine Linux system with root access
  • At least 2GB RAM (4GB recommended)
  • 20GB+ free disk space
  • 64-bit architecture
  • Kernel version 3.10 or higher

Step 1: System Preparation

Update System

# Update package repositories
sudo apk update

# Upgrade existing packages
sudo apk upgrade

# Install prerequisites
sudo apk add curl ca-certificates

Enable Community Repository

# Edit repositories file
sudo nano /etc/apk/repositories

Uncomment or add the community repository:

http://dl-cdn.alpinelinux.org/alpine/v3.18/main
http://dl-cdn.alpinelinux.org/alpine/v3.18/community

Update package list:

sudo apk update

Step 2: Install Docker

Install Docker Package

# Install Docker
sudo apk add docker

# Install Docker Compose
sudo apk add docker-compose

# Install additional tools
sudo apk add docker-cli docker-registry

Enable Docker Service

# Add Docker to boot services
sudo rc-update add docker boot

# Start Docker service
sudo rc-service docker start

# Check Docker status
sudo rc-service docker status

Step 3: Configure Docker

Add User to Docker Group

# Add current user to docker group
sudo addgroup $(whoami) docker

# Apply group changes (logout/login or use newgrp)
newgrp docker

# Verify access
docker run hello-world

Configure Docker Daemon

# Create Docker configuration
sudo nano /etc/docker/daemon.json

Add configuration:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ],
  "dns": ["8.8.8.8", "8.8.4.4"],
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": false,
  "experimental": false
}

Restart Docker:

sudo rc-service docker restart

Step 4: Verify Installation

Check Docker Version

# Docker version
docker --version

# Detailed version info
docker version

# System information
docker info

Run Test Container

# Run hello-world
docker run hello-world

# Run Alpine Linux container
docker run -it alpine:latest /bin/sh

# Inside container
cat /etc/alpine-release
exit

Step 5: Docker Compose Setup

Verify Docker Compose

# Check version
docker-compose --version

# Alternative: docker compose (newer syntax)
docker compose version

Create Sample Compose File

# Create project directory
mkdir ~/docker-demo
cd ~/docker-demo

# Create docker-compose.yml
nano docker-compose.yml

Add sample configuration:

version: '3.8'

services:
  web:
    image: nginx:alpine
    container_name: demo-nginx
    ports:
      - "8080:80"
    volumes:
      - ./html:/usr/share/nginx/html:ro
    restart: unless-stopped

  db:
    image: postgres:alpine
    container_name: demo-postgres
    environment:
      POSTGRES_DB: demo
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: unless-stopped

volumes:
  postgres_data:

Create HTML directory:

mkdir html
echo "<h1>Hello from Docker on Alpine!</h1>" > html/index.html

Start services:

# Start in background
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

Step 6: Docker Storage Configuration

Configure Storage Driver

# Check current storage driver
docker info | grep "Storage Driver"

# Configure device mapper (if needed)
sudo nano /etc/docker/daemon.json

Add storage configuration:

{
  "storage-driver": "devicemapper",
  "storage-opts": [
    "dm.thinpooldev=/dev/mapper/docker-thinpool",
    "dm.use_deferred_removal=true",
    "dm.use_deferred_deletion=true"
  ]
}

Set Up Docker Volumes

# Create custom volume
docker volume create mydata

# List volumes
docker volume ls

# Inspect volume
docker volume inspect mydata

# Use in container
docker run -v mydata:/data alpine touch /data/test.txt

Step 7: Network Configuration

Create Custom Networks

# Create bridge network
docker network create myapp-net

# Create with subnet
docker network create --subnet=172.20.0.0/16 custom-net

# List networks
docker network ls

# Inspect network
docker network inspect myapp-net

Connect Containers

# Run container on custom network
docker run -d --name app1 --network myapp-net alpine sleep 3600
docker run -d --name app2 --network myapp-net alpine sleep 3600

# Test connectivity
docker exec app1 ping app2

Step 8: Security Configuration

Enable User Namespaces

# Edit Docker daemon config
sudo nano /etc/docker/daemon.json

Add security options:

{
  "userns-remap": "default",
  "security-opts": ["no-new-privileges:true"],
  "icc": false,
  "live-restore": true,
  "userland-proxy": false
}

Configure Firewall

# Allow Docker traffic
sudo iptables -A INPUT -i docker0 -j ACCEPT

# Save rules
sudo iptables-save > /etc/iptables/rules.v4

Step 9: Resource Management

Set Container Limits

# Run with memory limit
docker run -m 512m --memory-swap 1g alpine

# Run with CPU limit
docker run --cpus="1.5" alpine

# Run with combined limits
docker run -m 1g --cpus="2" --name limited-container alpine

Monitor Resource Usage

# Real-time stats
docker stats

# Specific container
docker stats container_name

# Format output
docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"

Step 10: Docker Registry Setup

Run Local Registry

# Start registry
docker run -d -p 5000:5000 --name registry registry:2

# Tag image for local registry
docker tag alpine:latest localhost:5000/my-alpine

# Push to local registry
docker push localhost:5000/my-alpine

# Pull from local registry
docker pull localhost:5000/my-alpine

Configure Insecure Registry

# For HTTP registry
sudo nano /etc/docker/daemon.json

Add insecure registry:

{
  "insecure-registries": ["myregistry.local:5000"]
}

Common Docker Commands

Container Management

# List running containers
docker ps

# List all containers
docker ps -a

# Start/stop container
docker start container_name
docker stop container_name

# Remove container
docker rm container_name

# Remove all stopped containers
docker container prune

Image Management

# List images
docker images

# Pull image
docker pull alpine:latest

# Remove image
docker rmi image_name

# Remove unused images
docker image prune -a

Logs and Debugging

# View logs
docker logs container_name

# Follow logs
docker logs -f container_name

# Execute command in container
docker exec -it container_name /bin/sh

# Inspect container
docker inspect container_name

Troubleshooting

Docker Service Issues

# Check service status
sudo rc-service docker status

# View Docker logs
sudo tail -f /var/log/docker.log

# Test Docker daemon
sudo dockerd --debug

Permission Problems

# Fix socket permissions
sudo chmod 666 /var/run/docker.sock

# Verify group membership
groups $(whoami)

# Re-login to apply groups
su - $(whoami)

Storage Issues

# Check disk space
df -h

# Clean up Docker
docker system prune -a

# Remove volumes
docker volume prune

Best Practices

  1. Use Alpine-based images: Smaller size, better security
  2. Implement health checks: Monitor container health
  3. Use specific tags: Avoid :latest in production
  4. Limit resources: Prevent container resource abuse
  5. Regular cleanup: Remove unused images and containers
  6. Secure registries: Use HTTPS for image registries
  7. Network isolation: Use custom networks for applications

Monitoring Script

Create a monitoring script:

#!/bin/sh
# Docker monitoring script

echo "=== Docker System Status ==="
echo "Docker Version: $(docker --version)"
echo "Running Containers: $(docker ps -q | wc -l)"
echo "Total Images: $(docker images -q | wc -l)"
echo "Total Volumes: $(docker volume ls -q | wc -l)"
echo
echo "=== Resource Usage ==="
docker system df
echo
echo "=== Container Status ==="
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

Conclusion

You’ve successfully installed and configured Docker on Alpine Linux! Your system is now ready to:

  • ✅ Run containerized applications
  • ✅ Manage container networks
  • ✅ Use Docker Compose for multi-container apps
  • ✅ Implement security best practices
  • ✅ Monitor and maintain containers

Docker on Alpine Linux provides a powerful, lightweight platform for modern application deployment. Happy containerizing! 🐳