The Complete Docker Guide: Installation & Basics for Linux
Published on February 20, 2026 · 15 min read
Whether you’re a developer, sysadmin, or DevOps engineer, Docker has become one of the most essential tools in modern infrastructure. In this comprehensive guide, we’ll walk through installing Docker on the four most popular enterprise Linux distributions — CentOS Stream 9, Ubuntu, Red Hat Enterprise Linux (RHEL), and SUSE Linux — and then dive into practical Docker tutorials to get you up and running fast.
Table of Contents
- What is Docker?
- Installing Docker on CentOS Stream 9
- Installing Docker on Ubuntu
- Installing Docker on Red Hat Enterprise Linux (RHEL)
- Installing Docker on SUSE Linux
- Docker Basics: Your First Tutorials
- Running Your First Container
- Working with Images
- Writing a Dockerfile
- Docker Volumes
- Docker Networking
- Docker Compose
What is Docker?
Docker is an open-source platform that allows you to build, ship, and run applications inside containers — lightweight, portable environments that package your application code along with all its dependencies. Unlike virtual machines, containers share the host OS kernel, making them faster to start and more resource-efficient.
Think of a Docker container like a shipping container: it doesn’t matter whether it’s on a ship, a truck, or a train — it works the same way everywhere.
Installing Docker on CentOS Stream 9
CentOS Stream 9 is a rolling-release distribution that tracks just ahead of Red Hat Enterprise Linux. Docker is not available in the default CentOS repositories, so we’ll add Docker’s official repository.
Step 1: Update Your System
sudo dnf update -y
Step 2: Install Required Dependencies
sudo dnf install -y yum-utils device-mapper-persistent-data lvm2
Step 3: Add Docker’s Official Repository
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Step 4: Install Docker Engine
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 5: Start and Enable Docker
sudo systemctl start docker sudo systemctl enable docker
Step 6: Verify Installation
sudo docker --version sudo docker run hello-world
Step 7: Add Your User to the Docker Group (Optional but Recommended)
This allows you to run Docker commands without sudo:sudo usermod -aG docker $USER newgrp docker
Note: Log out and log back in for the group change to take effect.
Installing Docker on Ubuntu
Docker officially supports Ubuntu 20.04 LTS, 22.04 LTS, 23.x, and 24.04 LTS. The steps below work for all of them.
Step 1: Update and Install Prerequisites
sudo apt update sudo apt install -y ca-certificates curl gnupg lsb-release
Step 2: Add Docker’s 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
Step 3: Add the Docker Repository
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 4: Install Docker Engine
sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 5: Start and Enable Docker
sudo systemctl start docker sudo systemctl enable docker
Step 6: Verify Installation
sudo docker --version sudo docker run hello-world
Step 7: Run Docker Without sudo
sudo usermod -aG docker $USER newgrp docker
Installing Docker on Red Hat Enterprise Linux
Important Note: Docker Inc. does not officially publish Docker CE packages for RHEL. The recommended approach for RHEL is to use Podman (which is Docker-compatible) or to install Docker using the CentOS repository. We’ll cover the Docker CE method here using the CentOS repo, which works well on RHEL 8 and 9.
Method 1: Docker CE via CentOS Repo (RHEL 8/9)
Step 1: Remove Conflicting Packages
sudo dnf remove -y podman buildah
Step 2: Add Docker Repository
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Step 3: Install Docker
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 4: Start and Enable Docker
sudo systemctl start docker sudo systemctl enable docker
Step 5: Verify
sudo docker --version sudo docker run hello-world
Method 2: Using Podman (Native RHEL Alternative)
If you prefer staying fully within Red Hat’s ecosystem, Podman is an excellent drop-in replacement:sudo dnf install -y podman sudo dnf install -y podman-docker # Adds 'docker' alias
Podman is daemonless and runs rootless by default, which is great for security-conscious environments.
Installing Docker on SUSE Linux
Docker is supported on openSUSE Leap, openSUSE Tumbleweed, and SUSE Linux Enterprise Server (SLES).
For openSUSE Leap / Tumbleweed
Step 1: Add the Virtualization Repository
sudo zypper addrepo https://download.opensuse.org/repositories/Virtualization/openSUSE_Leap_15.5/Virtualization.repo sudo zypper refresh
Adjust the URL to match your version of openSUSE Leap (e.g.,
15.4,15.5).
Step 2: Install Docker
sudo zypper install -y docker
Step 3: Start and Enable Docker
sudo systemctl start docker sudo systemctl enable docker
Step 4: Add User to Docker Group
sudo usermod -aG docker $USER newgrp docker
For SUSE Linux Enterprise Server (SLES)
On SLES, Docker is available through the Containers module. You’ll need access to the SUSE Customer Center (SCC) or a registered system.sudo SUSEConnect -p sle-module-containers/15.5/x86_64 sudo zypper install -y docker sudo systemctl start docker sudo systemctl enable docker
Verify Installation (All SUSE)
docker --version docker run hello-world
Docker Basics: Your First Tutorials
Now that Docker is installed, let’s learn how to use it. These tutorials apply to all distributions.
Running Your First Container
The docker run command pulls an image and starts a container.# Run a simple hello-world test docker run hello-world # Run an Ubuntu container interactively docker run -it ubuntu bash # Inside the container, you can run any Ubuntu command: cat /etc/os-release exit
Key flags:
-i— Keep STDIN open (interactive mode)-t— Allocate a pseudo-TTY (terminal)-d— Run in detached (background) mode--name my-container— Assign a name to the container-p 8080:80— Map host port 8080 to container port 80
Example: Run an Nginx web server:docker run -d -p 8080:80 --name my-nginx nginx
Open your browser and go to http://localhost:8080 — you should see the Nginx welcome page.# Stop the container docker stop my-nginx # Remove the container docker rm my-nginx
Working with Images
Docker images are the blueprints for containers. They live in Docker Hub (the public registry) or private registries.# Search for an image docker search nginx # Pull an image docker pull nginx docker pull ubuntu:22.04 docker pull python:3.11-slim # List downloaded images docker images # Remove an image docker rmi nginx # Inspect an image docker inspect nginx
Image naming convention:[registry/][username/]image-name[:tag] Examples: nginx → nginx:latest from Docker Hub ubuntu:22.04 → Ubuntu 22.04 specifically python:3.11-slim → Python 3.11 slim variant myrepo/myapp:v1.0 → Custom image from a user's repo
Writing a Dockerfile
A Dockerfile is a text file with instructions to build your own custom Docker image. Think of it as a recipe.
Example: Dockerize a simple Python Flask app
First, create your app files:mkdir my-flask-app && cd my-flask-app
Create app.py:from flask import Flask app = Flask(__name__) @app.route('/') def home(): return "<h1>Hello from Docker!</h1>" if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)
Create requirements.txt:flask==3.0.0
Now create the Dockerfile:# Base image FROM python:3.11-slim # Set working directory inside the container WORKDIR /app # Copy requirements first (for better caching) COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the app COPY . . # Expose the port EXPOSE 5000 # Command to run the application CMD ["python", "app.py"]
Build and run:# Build the image docker build -t my-flask-app:v1.0 . # Run the container docker run -d -p 5000:5000 --name flask-app my-flask-app:v1.0 # Test it curl http://localhost:5000
Common Dockerfile instructions: Instruction Purpose FROM Sets the base image WORKDIR Sets the working directory COPY Copies files from host to image ADD Like COPY but supports URLs and tar extraction RUN Executes commands during build ENV Sets environment variables EXPOSE Documents the port the app uses CMD Default command to run when container starts ENTRYPOINT Like CMD but harder to override
Docker Volumes
By default, data inside a container is lost when the container is removed. Volumes are Docker’s way of persisting data.# Create a named volume docker volume create mydata # List volumes docker volume ls # Run a container with a volume docker run -d \ --name my-mysql \ -e MYSQL_ROOT_PASSWORD=secret \ -v mydata:/var/lib/mysql \ mysql:8.0 # Inspect a volume docker volume inspect mydata # Remove a volume docker volume rm mydata
You can also use bind mounts to mount a host directory into a container:# Mount current directory into the container docker run -d \ -p 8080:80 \ -v $(pwd)/html:/usr/share/nginx/html \ --name web nginx
Any changes you make to ./html on the host will be immediately reflected inside the container. This is great for development!
Docker Networking
Docker automatically creates a default bridge network. Containers on the same network can communicate with each other by container name.# List networks docker network ls # Create a custom network docker network create mynetwork # Run containers on the same network docker run -d --name db --network mynetwork mysql:8.0 -e MYSQL_ROOT_PASSWORD=secret docker run -d --name app --network mynetwork my-flask-app:v1.0 # Inside the 'app' container, you can reach 'db' by hostname 'db' # Inspect a network docker network inspect mynetwork # Remove a network docker network rm mynetwork
Network types:
bridge— Default. Containers talk to each other but are isolated from the host network.host— Container shares the host’s network stack directly.none— No networking at all.overlay— Used in Docker Swarm for multi-host networking.
Docker Compose
Docker Compose lets you define and run multi-container applications using a single YAML file. It’s perfect for development environments.
Example: A WordPress + MySQL stack
Create a docker-compose.yml file:version: '3.8' services: db: image: mysql:8.0 restart: always environment: MYSQL_ROOT_PASSWORD: rootpassword MYSQL_DATABASE: wordpress MYSQL_USER: wpuser MYSQL_PASSWORD: wppassword volumes: - db_data:/var/lib/mysql networks: - wp-network wordpress: image: wordpress:latest restart: always ports: - "8080:80" environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: wpuser WORDPRESS_DB_PASSWORD: wppassword volumes: - wp_data:/var/www/html networks: - wp-network depends_on: - db volumes: db_data: wp_data: networks: wp-network:
Run it:# Start all services in background docker compose up -d # Check running services docker compose ps # View logs docker compose logs -f # Stop all services docker compose down # Stop and remove volumes too docker compose down -v
Visit http://localhost:8080 and you’ll have a fully working WordPress instance!
Useful Docker Commands Cheat Sheet
# ── CONTAINERS ───────────────────────────────────────────── docker run [options] IMAGE # Create and start a container docker start CONTAINER # Start a stopped container docker stop CONTAINER # Gracefully stop a container docker kill CONTAINER # Force-stop a container docker restart CONTAINER # Restart a container docker rm CONTAINER # Remove a stopped container docker rm -f CONTAINER # Force remove (even if running) docker ps # List running containers docker ps -a # List all containers docker exec -it CONTAINER bash # Open shell in running container docker logs CONTAINER # View container logs docker logs -f CONTAINER # Follow logs in real time docker inspect CONTAINER # Detailed JSON info docker stats # Live resource usage stats docker cp file.txt CONTAINER:/path # Copy file into container # ── IMAGES ───────────────────────────────────────────────── docker images # List local images docker pull IMAGE # Download an image docker push IMAGE # Upload image to registry docker build -t NAME:TAG . # Build image from Dockerfile docker rmi IMAGE # Remove an image docker image prune # Remove unused images docker tag IMAGE NEW_NAME:TAG # Tag an image # ── VOLUMES ──────────────────────────────────────────────── docker volume ls # List volumes docker volume create NAME # Create a volume docker volume rm NAME # Remove a volume docker volume prune # Remove unused volumes # ── NETWORKS ─────────────────────────────────────────────── docker network ls # List networks docker network create NAME # Create a network docker network rm NAME # Remove a network docker network inspect NAME # Inspect a network # ── SYSTEM ───────────────────────────────────────────────── docker system df # Show disk usage docker system prune # Remove all unused resources docker system prune -a # Remove everything not in use docker info # System-wide Docker info docker version # Docker version details
Final Thoughts
Docker is a powerful tool that simplifies application deployment and environment consistency across every Linux distribution. Whether you’re running CentOS, Ubuntu, RHEL, or SUSE — the workflow is the same once Docker is installed.
Here’s a quick recap of what we covered:
- Installing Docker on CentOS Stream 9, Ubuntu, RHEL, and SUSE Linux
- Running your first containers
- Building custom images with Dockerfiles
- Persisting data with volumes
- Connecting containers with networks
- Orchestrating multi-container apps with Docker Compose
The best way to learn Docker is to keep experimenting. Try containerizing one of your own projects, spin up a database, or explore Docker Hub for ready-to-use images. The ecosystem is vast and incredibly well-documented.
Happy Dockerizing! 🐳
Found this guide helpful? Share it with your team and follow for more Linux and DevOps tutorials.