New users get $100 in free credits for 30 daysGet Started

Introducing local edge computing in 5 new African citiesLearn More

Join our webinar: Scaling your startup on African infrastructureRegister Now

How to Install Docker on Ubuntu, CentOS, and Windows

Sarah Wilson
Sarah Wilson
December 8, 2024
15 min read
DockerContainerizationDevOpsIntermediate

What is Docker?

Docker is a containerization platform that allows you to package applications and their dependencies into lightweight, portable containers. These containers can run consistently across different environments, from development laptops to production servers.

Docker containers are similar to virtual machines but much more efficient. They share the host OS kernel and use fewer resources while providing the same isolation benefits.

Why Use Docker?
  • Consistency: Applications run the same way everywhere
  • Efficiency: Lightweight compared to virtual machines
  • Scalability: Easy to scale applications up or down
  • Portability: Move applications between environments easily

Prerequisites

Before installing Docker, ensure you have:

  • A 64-bit operating system
  • Administrative/root access to your system
  • At least 4GB of RAM (8GB recommended)
  • Virtualization enabled in BIOS (for Windows)

Installing Docker on Ubuntu

Ubuntu provides an easy way to install Docker using the official Docker repository. This method ensures you get the latest version with security updates.

  1. Update Package Index

    First, update your existing list of packages:

    Terminal
    sudo apt update
  2. Install Prerequisites

    Install packages that allow apt to use repositories over HTTPS:

    Terminal
    sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
  3. Add Docker's GPG Key

    Add Docker's official GPG key:

    Terminal
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  4. Add Docker Repository

    Set up the stable repository:

    Terminal
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  5. Install Docker Engine

    Update the apt package index and install Docker Engine:

    Terminal
    sudo apt update
    sudo apt install docker-ce docker-ce-cli containerd.io
  6. Add User to Docker Group

    Add your user to the docker group to run Docker without sudo:

    Terminal
    sudo usermod -aG docker $USER

    Note: Log out and back in for this change to take effect.

Installing Docker on CentOS

CentOS installation is similar to Ubuntu but uses yum/dnf package manager instead of apt.

  1. Remove Old Versions

    Remove any older versions of Docker:

    Terminal
    sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
  2. Install Required Packages

    Install the yum-utils package:

    Terminal
    sudo yum install -y yum-utils
  3. Add Docker Repository

    Set up the Docker repository:

    Terminal
    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  4. Install Docker Engine

    Install Docker Engine, containerd, and Docker Compose:

    Terminal
    sudo yum install docker-ce docker-ce-cli containerd.io
  5. Start Docker Service

    Start and enable Docker service:

    Terminal
    sudo systemctl start docker
    sudo systemctl enable docker

Installing Docker on Windows

Docker Desktop for Windows provides an easy way to run Docker on Windows 10/11 with WSL 2 (Windows Subsystem for Linux) backend.

  1. System Requirements

    Ensure your system meets the requirements:

    • Windows 10 64-bit: Pro, Enterprise, or Education (Build 16299 or later)
    • Windows 11 64-bit: Home or Pro version 21H2 or higher
    • WSL 2 feature enabled
    • Virtualization enabled in BIOS
    • At least 4GB RAM
  2. Enable WSL 2

    Open PowerShell as Administrator and run:

    PowerShell (Admin)
    wsl --install

    Restart your computer when prompted.

  3. Download Docker Desktop

    Visit docker.com/docker-desktopand download Docker Desktop for Windows.

  4. Install Docker Desktop

    Run the installer and follow the installation wizard. Make sure to:

    • Enable "Use WSL 2 instead of Hyper-V" option
    • Add shortcut to desktop (optional)
  5. Start Docker Desktop

    Launch Docker Desktop from the Start menu. It may take a few minutes to start the first time as it sets up the WSL 2 integration.

Windows Home Users

If you're using Windows 10 Home, you'll need to upgrade to Windows 10 Pro or use Docker Toolbox (legacy solution) instead of Docker Desktop.

Verify Installation

After installing Docker, verify that it's working correctly by running a test container:

Terminal
docker --version

You should see output similar to:

Output
Docker version 24.0.7, build afdd53b

Now run the hello-world container to verify Docker is working:

Terminal
docker run hello-world

This command downloads a test image and runs it in a container. If successful, you'll see a "Hello from Docker!" message.

Basic Docker Commands

Now that Docker is installed, here are some essential commands to get you started:

Container Management

Terminal
# List running containers
docker ps

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

# Run a container
docker run nginx

# Run a container in detached mode
docker run -d nginx

# Stop a container
docker stop <container_id>

# Remove a container
docker rm <container_id>

Image Management

Terminal
# List images
docker images

# Pull an image from Docker Hub
docker pull ubuntu

# Remove an image
docker rmi <image_id>

# Build an image from Dockerfile
docker build -t myapp .

System Information

Terminal
# Show Docker system information
docker info

# Show Docker disk usage
docker system df

# Clean up unused resources
docker system prune

Conclusion

Congratulations! You've successfully installed Docker on your system. Docker is now ready to help you containerize your applications and streamline your development workflow.

Next steps you might consider:

  • Learn about Dockerfile and how to create custom images
  • Explore Docker Compose for multi-container applications
  • Set up a container registry for your images
  • Learn about Docker networking and volumes
  • Explore container orchestration with Kubernetes
Success!

You're now ready to start containerizing your applications with Docker. Happy containerizing!

About the Author

Sarah Wilson
Sarah Wilson
Cloud Solutions Architect with expertise in containerization and microservices architecture.

Need Docker Hosting?

Deploy your containers on our managed Kubernetes platform.

Explore Kubernetes