Installing Docker on Ubuntu 22.04 is a simple process that lets you run and manage containers seamlessly. Docker has become a go-to tool for developers and system admins because it simplifies application deployment across different environments. In this article, we’ll walk through the steps to get Docker up and run on your Ubuntu machine. Whether you’re new to containerization or just need a refresher, this guide covers everything from prerequisites to verification.
Before we dive in, make sure your system meets the basic requirements. You’ll need a 64-bit Ubuntu 22.04 installation and administrative access via sudo. Let’s get started.
Prerequisites
To ensure smooth installation, check these items first:
- An Ubuntu 22.04 LTS server or desktop setup.
- A user account with sudo privileges.
- Internet access to download packages.
- At least 2 GB of RAM and some free disk space for containers.
If you have older versions of Docker installed, like docker.io or containerd, it’s best to remove them to avoid conflicts.
How to install Docker on Ubuntu 22.04
Step 1: Uninstall Old Docker Versions
Start by cleaning up any previous installations. Open your terminal and run these commands:
Update your package index:
sudo apt update
Remove old packages:
sudo apt remove docker docker-engine docker.io containerd runc
This step helps prevent version mismatches during the new install.
Step 2: Set Up the Docker Repository
Docker recommends installing from their official repository for the latest stable version. Here’s how:
Install required packages for HTTPS support:
sudo apt install ca-certificates curl gnupg lsb-release
Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /etc/apt/keyrings/docker.gpg
Set up the repository:
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
These commands prepare your system to fetch Docker packages securely.
Step 3: Install Docker Engine
Now, pull in the latest Docker packages:
Update the package index again:
sudo apt update
Install the core components:
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
This installs Docker Engine, the CLI, and other essentials. The process might take a few minutes depending on your connection.
Step 4: Verify the Installation
To confirm everything works, test Docker with a simple container:
Start the Docker service:
sudo systemctl start docker
Enable it to run on boot:
sudo systemctl enable docker
Run a test container:
sudo docker run hello-world
If you see a message saying, “Hello from Docker!”, you’re all set. This verifies that Docker can pull images and run containers properly.
Post-Installation Steps
By default, Docker commands require sudo. To run them as a non-root user:
Add your user to the docker group:
sudo usermod -aG docker $USER
Log out and back in or run newgrp docker to apply changes.
This makes working with Docker more convenient without constant sudo prompts.
If you’re behind a proxy, configure Docker to use it by editing /etc/systemd/system/docker.service.d/http-proxy.conf and reloading the service.
Common Tips for Using Docker on Ubuntu 22.04
Once installed, here are some quick tips:
- Pull images: Use docker pull image-name to download from Docker Hub.
- Manage containers: Commands like docker ps, docker start, and docker stop help oversee your setups.
- Update Docker: Regularly run sudo apt update && sudo apt upgrade to keep things current.
Installing Docker on Ubuntu 22.04 opens up a world of containerized apps, from web servers to databases.
FAQs
Do I need to reboot after installing Docker on Ubuntu 22.04?
No, a full reboot isn’t necessary. Just log out and back in if you added your user to the docker group or restart the Docker service with sudo systemctl restart docker.
What if I get a permission denied error when running Docker commands?
This usually means your user isn’t in the docker group. Add it with sudo usermod -aG docker $USER and re-login.
How do I uninstall Docker if needed?
To remove Docker, use: sudo apt purge docker-ce docker-ce-cli containerd.io docker-compose-plugin. Then, delete images and configs with sudo rm -rf /var/lib/docker.
Is Docker Compose included in this installation?
Yes, the docker-compose-plugin package includes Docker Compose V2, which you can use as docker compose instead of the old docker-compose.
Can I install a specific version of Docker?
Absolutely. Check available versions with apt-cache madison docker-ce, then install like sudo apt install docker-ce=<VERSION_STRING>.