Docker / Podman
This article covers how to install and use Docker and Podman container technologies on Ubuntu 26.04.
Installing Docker CE
Remove Old Versions
sudo apt remove docker docker-engine docker.io containerd runc 2>/dev/nullInstall Docker CE
# Install dependencies
sudo apt update
sudo apt install ca-certificates curl gnupg -y
# Add Docker official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add Docker repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -yUse Docker Without sudo
# Add current user to the docker group
sudo usermod -aG docker $USER
# Apply group changes (or log out and back in)
newgrp dockerVerify Installation
docker --version
docker compose version
docker run hello-worldConfigure Docker Mirror (China)
Edit /etc/docker/daemon.json:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker.xuanyuan.me"
]
}
EOF
# Restart Docker
sudo systemctl daemon-reload
sudo systemctl restart dockerDocker Basics
Image Operations
# Pull an image
docker pull ubuntu:26.04
docker pull nginx:latest
# List local images
docker images
# Remove an image
docker rmi nginx:latest
# Build an image
docker build -t myapp:latest .
# Clean up unused images
docker image prune -aContainer Operations
# Run a container
docker run -d --name mynginx -p 8080:80 nginx
# List running containers
docker ps
# List all containers
docker ps -a
# Enter a container
docker exec -it mynginx bash
# View container logs
docker logs -f mynginx
# Stop and remove a container
docker stop mynginx
docker rm mynginx
# Clean up all stopped containers
docker container pruneVolumes
# Create a volume
docker volume create mydata
# Mount a volume
docker run -d -v mydata:/data --name mycontainer ubuntu
# Mount a host directory
docker run -d -v /home/user/data:/data --name mycontainer ubuntu
# List volumes
docker volume ls
docker volume inspect mydataDocker Compose
Docker Compose is used to define and run multi-container applications.
Example: Web App + Database
Create compose.yaml:
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html
depends_on:
- db
db:
image: postgres:18
environment:
POSTGRES_DB: mydb
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
pgdata:Common Compose Commands
# Start all services
docker compose up -d
# Check service status
docker compose ps
# View logs
docker compose logs -f web
# Stop all services
docker compose down
# Stop and remove volumes
docker compose down -v
# Rebuild and start
docker compose up -d --buildWriting a Dockerfile
A typical multi-stage build example:
# Build stage
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Runtime stage
FROM node:22-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/index.js"]Podman: An Alternative to Docker
Podman is a daemonless container engine that is compatible with the Docker CLI.
Install Podman
sudo apt install podman -yVerify the installation:
podman --version
podman infoPodman Basics
Podman commands are nearly identical to Docker:
# Pull and run a container
podman pull docker.io/library/nginx
podman run -d --name mynginx -p 8080:80 nginx
# List containers
podman ps
# Stop and remove
podman stop mynginx
podman rm mynginxDifferences Between Podman and Docker
- Daemonless: Podman does not require a background daemon process
- Rootless: Podman runs containers as a regular user by default, providing better security
- Pod support: Podman natively supports the Pod concept (similar to Kubernetes Pods)
- Compatibility: The vast majority of Docker commands can be directly replaced with Podman
Set Up Docker Compatibility Alias
echo 'alias docker=podman' >> ~/.bashrc
source ~/.bashrcPodman Compose
# Install podman-compose (prefer apt or pipx to avoid the PEP 668 restriction)
sudo apt install -y podman-compose
# Or: sudo apt install -y pipx && pipx install podman-compose
# Usage is the same as docker compose
podman-compose up -d
podman-compose downDocker System Maintenance
# Check disk usage
docker system df
# Full cleanup (use with caution)
docker system prune -a --volumes
# Check Docker service status
sudo systemctl status dockerDocker and Podman each have their strengths. Docker has a more mature ecosystem, while Podman offers better security and doesn’t require a daemon. Choose based on your needs.
FAQ
Should I choose Docker or Podman?
If you’re a beginner or need to collaborate with a team, Docker is recommended because it has a more mature ecosystem, richer documentation, and broader community support. If you prioritize security or work in an environment without root privileges, Podman is the better choice since it doesn’t require a daemon and runs as a non-root user by default.
Can I use the Snap version of Docker?
The docker.io package in the Ubuntu repository and the Snap version of Docker can be used, but they typically lag behind the official Docker CE in version and may have compatibility issues. We recommend installing Docker CE from the official Docker repository as described in this article for the latest version and best compatibility.
Do I need sudo to use Docker?
By default, sudo privileges are required to run Docker commands. After adding your user to the docker group, you can use Docker without sudo (run sudo usermod -aG docker $USER then log out and back in). Note that being in the docker group is equivalent to having root privileges, so use caution in multi-user environments.
Related Articles
- Docker Compose Service Orchestration — Deploy multi-container applications with Docker Compose in a server environment
- Virtual Machines & Containers — Compare VM and container technologies to understand their respective use cases