Install Docker on Ubuntu

Install Docker on Ubuntu

Learn how to install Docker on Ubuntu in a few simple steps.

Alex Rodriguez
2024-01-10
2 min read
Table of Contents

To install Docker on Ubuntu, follow these steps:

Step 1: Uninstall Old Versions (If Any)

If you have an older version of Docker installed, remove it first:

SH
sudo apt remove docker docker-engine docker.io containerd runc

Step 2: Update Package List

Update the package index and install dependencies:

SH
sudo apt update
sudo apt install -y ca-certificates curl gnupg

Step 3: Add Docker’s Official GPG Key

SH
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo tee /etc/apt/keyrings/docker.gpg > /dev/null
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Step 4: Add Docker Repository

SH
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

Then, update the package list again:

SH
sudo apt update

Step 5: Install Docker Engine, CLI, and Containerd

SH
sudo apt 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:

SH
docker --version

Start the Docker service:

SH
sudo systemctl start docker
sudo systemctl enable docker

Test Docker with a Hello World container:

SH
sudo docker run hello-world

Step 7: Run Docker Without sudo (Optional)

By default, Docker requires root privileges. To allow your user to run Docker without sudo:

SH
sudo usermod -aG docker $USER

Then, log out and log back in or run:

SH
newgrp docker

Now, try running:

SH
docker ps

Step 8: Enable Docker to Start on Boot

SH
sudo systemctl enable docker

Bonus: Install Docker Compose

Docker Compose allows you to run multi-container applications. Install it using:

SH
sudo apt install -y docker-compose-plugin

Verify installation:

SH
docker compose version
Share this article:
42 likes
Alex Rodriguez

Alex Rodriguez

JavaScript Instructor

JavaScript expert and former bootcamp instructor. Specializes in making complex concepts simple and engaging for new developers.

Related Articles

Install Java on Ubuntu
#Java
#Installation

Install Java on Ubuntu

Learn how to install Java on Ubuntu in a few simple steps.

Read More
Install Node.js Using NVM
#Node.js
#NVM

Install Node.js Using NVM

Learn how to install Node.js using NVM (Node Version Manager) on Linux in a few simple steps.

Read More
Fix Line Ending Issues in VS Code
#VS Code
#Line Endings

Fix Line Ending Issues in VS Code

Learn how to fix CRLF (Carriage Return + Line Feed) and LF (Line Feed) issues in VS Code for consistent line endings in your files.

Read More
Comprehensive Guide to Package Managers in Software Development
#Package Managers
#NPM

Comprehensive Guide to Package Managers in Software Development

A detailed comparison of package managers across different programming languages to help you choose the best one for your development journey.

Read More

Never Miss an Update

Get the latest tutorials, tips, and insights delivered straight to your inbox.

No spam, unsubscribe at any time.