Installing Docker on Ubuntu transforms your machine into a powerful virtualization host, allowing you to package software together with all its necessary dependencies.
Whether you are setting up a local lab or a production server, Linux provides built-in package managers to handle the installation securely. This guide explains three practical methods to get Docker running, from the standard APT repository to portable Snap packages.
Table of Contents
Key Takeaways: Mastering Docker Installation
- APT (Advanced Package Tool) → The standard system used by Ubuntu to install, update, and remove software packages.
- Docker Engine → The core runtime (package name docker.io) that enables you to build and run containers.
- Sudo Privileges → Administrative rights are mandatory for installing software and managing the Docker daemon.
- Snap Packages → A portable software format that bundles dependencies, offering an alternative way to run Docker.
- System Integrity → Always update your package index before installation to ensure you receive the latest security patches.
Method 1: Installing Docker via APT (Recommended)
The most reliable way to install Docker on Ubuntu is through the official repositories using the APT package manager. This method ensures the software is optimized for your specific Ubuntu version.
1. Update the Package List Before installing, synchronize your local database with the global repositories: sudo apt update
2. Install Docker and Compose Use the following command to install the Docker engine and the Docker Compose plugin simultaneously: sudo apt-get install -y docker.io docker-compose
3. Verify the Installation Check the version to confirm the service is active: docker --version
Expected Output: Docker version 24.0.7, build 24.0.7-0ubuntu4
Method 2: Installing via the Ubuntu Snapshot Service
For production environments requiring a specific historical version of Docker, you can use the Ubuntu Snapshot Service. This allows you to install packages from a time-specific state of the archive.
Command: sudo apt install docker.io --snapshot 20240501T120000Z
This is particularly useful when you need to manage APT repositories to maintain consistency across a large cluster of servers.
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
Method 3: Using the Docker Snap
If you prefer a self-contained installation that doesn’t interfere with your system libraries, Canonical provides an official Docker snap. Snaps are ideal for users who want the latest version of Docker regardless of their Ubuntu release cycle.
Command: sudo snap install docker
Step-by-Step Process: Running Your First Container
Once Docker is installed, follow these steps to verify it is working by launching a standard web server container:
- Launch your terminal and verify you have administrative access by understanding the Linux sudo command.
- Pull and run the image: Execute
sudo docker run --name my-web-server -d ubuntu/apache2. - Check container status: Run
docker psto see the active container. - Inspect the container: Use
docker inspect my-web-serverto view networking and storage details. - Audit storage: You can check file size in Linux within the Docker volume directory at
/var/lib/docker/volumes. - Stop the service: When finished, run
docker stop my-web-server.
Summary Tables
| Goal | Recommended Command | Purpose |
|---|---|---|
| Standard Install | sudo apt install docker.io | Best for most Ubuntu servers. |
| Install Compose | sudo apt install docker-compose | For managing multi-container apps. |
| Update Index | sudo apt update | Refreshes the package database. |
| Check Version | docker --version | Verifies successful installation. |
| Remove Docker | sudo apt remove docker.io | Uninstalls the software binaries. |
| Installation Feature | APT Method | Snap Method |
|---|---|---|
| Maintenance | Supported by Canonical | Supported by Snapcraft |
| Dependencies | Uses shared system libraries | Self-contained/Sandboxed |
| Ease of Use | Standard CLI workflow | Auto-updating background |
FAQs
What is the difference between docker.io and docker-ce? docker.io is the package maintained and supported directly by Ubuntu/Canonical. docker-ce (Community Edition) is the version maintained by Docker Inc. For standard Ubuntu stability, docker.io is recommended.
Do I always need to use sudo with Docker? Yes, by default, the Docker daemon binds to a Unix socket owned by the root user. You must use the sudo command unless you add your user to the “docker” group.
Can I install Docker on older Ubuntu versions? Yes, but you may need to manually manage the /etc/apt/sources.list file if you are using a version prior to Ubuntu 24.04 LTS.


