Docker is a powerful platform for developing, shipping, and running applications inside containers. This guide will walk you through the process of installing Docker on Ubuntu Server 22.04 LTS.
Prerequisites
- Ubuntu Server 22.04 LTS installed and running.
- A user account with sudo privileges.
- Internet connection.
Step 1: Update Your System
Before installing Docker, it’s essential to update your system to ensure all existing packages are up to date.
sudo apt update
sudo apt upgrade -y
Step 2: Install Required Packages
Install a few prerequisite packages which let apt
use packages over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
Step 3: Add Docker’s Official GPG Key
Add Docker’s official GPG key to your system to ensure that the software is downloaded from a trusted source.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 4: Set Up the Docker Repository
Add the Docker APT repository to your system’s software repository list.
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
Step 5: Install Docker
- Update the package database with the Docker packages from the newly added repo: sudo apt update
- Ensure you are about to install from the Docker repo instead of the default Ubuntu repo: apt-cache policy docker-ce
- Install Docker:
sudo apt update
sudo apt install docker-ce -y
Step 6: Start and Enable Docker
Once the installation is complete, start the Docker service and enable it to start on boot:
sudo systemctl start docker
sudo systemctl enable docker
Step 7: Verify Docker Installation
To verify that Docker is installed correctly, run the following command:
sudo docker --version
You should see output similar to this, indicating the installed Docker version:
Docker version 20.10.7, build f0df350
Step 8: Run a Test Docker Container
To ensure Docker is working correctly, run a test container using the hello-world
image:
sudo docker run hello-world
You should see output that starts with:
Hello from Docker!
This message shows that your installation appears to be working correctly.
Step 9: Manage Docker as a Non-root User (Optional)
To avoid using sudo
with Docker commands, add your user to the Docker group:
sudo usermod -aG docker $USER
Log out and log back in so that your group membership is re-evaluated.
Step 10: Configure Docker to Start on Boot
By default, Docker is configured to start on boot. You can verify this with:
sudo systemctl is-enabled docker
This should return enabled
. If it doesn’t, enable Docker to start on boot:
sudo systemctl enable docker
You have successfully installed Docker on Ubuntu Server 22.04 LTS. You can now begin using Docker to create, manage, and run containers on your server. Docker provides a versatile environment for developing and deploying applications in a consistent and isolated environment.