Skip to main content

Docker Installation on Ubuntu

·
Ubuntu Docker Installation Linux Tutorial
Table of Contents

πŸš€ Installing Docker on an Ubuntu System
#

Docker is a powerful platform for developing, shipping, and running applications in containers. This guide will walk you through setting up Docker’s apt repository and installing it on an Ubuntu system.


βœ… Prerequisites
#

  • πŸ–₯️ Ubuntu 20.04+ (or a later version)
  • πŸ”‘ User account with sudo privileges
  • 🌐 Stable internet connection

πŸ”„ Step 1: Update Package Index
#

First, update the package list to ensure you have the latest information:

sudo apt-get update && sudo apt-get upgrade -y

πŸ“¦ Step 2: Install Required Dependencies
#

Install necessary packages to allow apt to use a repository over HTTPS:

sudo apt-get install -y ca-certificates curl

πŸ”‘ Step 3: Add Docker’s Official GPG Key
#

Set up the directory for key storage, download Docker’s official GPG key, and set correct permissions:

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

πŸ“‚ Step 4: Add the Repository to Apt Sources
#

Add Docker’s stable repository to your system’s package sources:

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] 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 list again:

sudo apt-get update

πŸ› οΈ Step 5: Install Docker Engine
#

To install the latest version of Docker, run:

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

πŸ” Step 6: Verify Docker Installation
#

Check if Docker is installed correctly by running:

docker --version

To test if Docker is working properly, run the hello-world container:

sudo docker run hello-world

πŸ‘€ Step 7: Manage Docker as a Non-Root User (Optional)
#

To avoid using sudo every time you run Docker, add your user to the docker group:

sudo usermod -aG docker $USER

Log out and back in, or run:

newgrp docker

πŸ”„ Step 8: Enable Docker to Start on Boot
#

Ensure Docker starts automatically on system boot:

sudo systemctl enable docker && sudo systemctl start docker

❌ Uninstalling Docker (If Needed)
#

If you need to remove Docker, use the following command:

sudo apt-get remove -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && sudo apt-get autoremove -y

If you also want to delete all Docker data (containers, images, volumes, etc.), run:

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

This will completely remove Docker from your system.


πŸŽ‰ Conclusion
#

You have successfully installed Docker on your Ubuntu system. You can now start using Docker to create, manage, and run containers efficiently. 🚒🐳

πŸ“– For more information, visit the official Docker documentation:
πŸ”— Docker Installation Guide