How to Install Docker Engine on Ubuntu (Debian)



This content originally appeared on DEV Community and was authored by coder7475

📌 This is a follow-up to my previous post: How Docker Works Internally

Before you can install Docker Engine on a fresh Ubuntu (or Debian-based) system, you need to set up Docker’s official apt repository. Once configured, you’ll be able to install and update Docker packages directly from Docker’s maintained repositories, ensuring you’re always using the latest stable versions.-

1. Set up Docker’s apt repository

Follow these steps to configure the repository:

# Update package index and install prerequisites:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg

# Create a directory for Docker's GPG key:
sudo install -m 0755 -d /etc/apt/keyrings

# Download Docker's official GPG key and convert to gpg format:
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's repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update the package index again:
sudo apt-get update

2. Install Docker packages

Install the latest version of Docker Engine and its components:

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

✅ The docker-buildx-plugin is included here, enabling advanced build features such as multi-platform builds.

3. Check Docker and containerd status

Verify that Docker and containerd services are running:

sudo systemctl status containerd
sudo systemctl status docker

If either service is inactive, start them using:

sudo systemctl start containerd
sudo systemctl start docker

4. Verify the installation

Run the hello-world image to confirm Docker is working correctly:

sudo docker run hello-world

This command downloads a test image, runs it in a container, and prints a confirmation message.

5. Run Docker without sudo

To avoid using sudo with every Docker command, add your user to the Docker group:

sudo usermod -aG docker $USER
newgrp docker

6. Final verification

Run the hello-world image again, this time without sudo:

docker run hello-world

7. (Optional) Enable and verify Docker Buildx

If you want to use advanced features like multi-platform builds, remote caching, or custom builders, set up Docker Buildx.

🔍 Check if Buildx is available:

docker buildx version

Expected output:

github.com/docker/buildx v0.11.2-docker ...

If no version is shown or you get an error, restart Docker:

sudo systemctl restart docker

🛠 Initialize and bootstrap a new builder:

docker buildx create --use --name mybuilder
docker buildx inspect --bootstrap

This ensures you’re ready for multi-architecture builds.

✅ Confirm the builder is ready:

docker buildx ls

You should see your builder (mybuilder) marked as current and bootstrapped.

✅ Example Workflow

docker buildx create --use --name mybuilder 
docker buildx inspect --bootstrap 

docker buildx build --platform linux/amd64,linux/arm64 -t myimage:latest .

This builds your image for both amd64 and arm64 architectures.

References

  1. Docker Documentation
  2. Docker Buildx Docs
  3. Docker Installation Challenge


This content originally appeared on DEV Community and was authored by coder7475