Docker enables containerization of applications with their dependencies, providing a standardized deployment environment. This guide covers the installation process on Ubuntu 22.04.
System Update
Begin by updating the package repository and upgrading existing packages:
sudo apt update
sudo apt full-upgrade -y
Install Required Dependencies
Add essential packages for secure repository access:
sudo apt install ca-certificates curl gnupg lsb-release -y
Add Docker GPG Key
Import Docker's official GPG key for package verification:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Configure Docker Repository
Add the Docker repository to your system sources:
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
Refresh Package Index
Update the package list to include Docker packages:
sudo apt update
Install Docker Engine
Install the Docker components:
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
Start and Enable Docker Service
Activate Docker and configure it to start on boot:
sudo systemctl enable docker
sudo systemctl start docker
Verify Installation
Test the Docker installation with a sample container:
sudo docker run --rm hello-world
Successful output should display confirmation messages from the Docker container.
Non-Root User Access
Add your user to the docker group to run commands without sudo:
sudo groupadd docker
sudo usermod -aG docker $USER
Log out and back in for group membership changes to take effect, or use:
newgrp docker
Install Docker Compose
For managing multi-container applications, install Docker Compose:
sudo apt install docker-compose-plugin -y
Verify the installation with:
docker compose version