Docker Installation on Ubuntu
This guide covers two methods for installing Docker Engine on Ubuntu systems: the automated script approach and the manual repository configuration.
Method 1: Automated Installation Script
The fastest way to install Docker is using the official convenience script with a mirror for better download speeds:
curl -fsSL https://get.docker.com -o install-docker.sh
sudo sh install-docker.sh --mirror Aliyun
Method 2: Manual Repository Setup
Step 1: Prepare Package Dependencies
Update the package index and install required dependencies:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common gnupg
Step 2: Add Docker GPG Key
Add the official Docker repository key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Note: The
apt-keycommand is deprecated in newer Debian/Ubuntu versions. Modern systems use/etc/apt/trusted.gpg.d/directory for keyring file management. This deprecation warning does not affect the installation functionality.
Step 3: Configrue Docker Repository
Add the official Docker repository for your Ubuntu release:
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
Update the package index and install Docker Engine:
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 4: Verify Installation
Check the installed Docker version:
docker --version
Docker Compose Installatoin
For Docker Engine with Built-in Compose Plugin
Recent Docker Engine versions (v2.29.1+) include the Compose plugin as part of the installation. The plugin is invoked via docker compose (with space) instead of the standalone docker-compose command.
Standalone Compose Binary (Legacy)
For older Docker versions or standalone installation, manual download and install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
To download a specific version (e.g., v2.11.2):
sudo curl -L "https://github.com/docker/compose/releases/download/v2.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Parameter breakdown:
$(uname -s)— Returns the operating system name (e.g., Linux)$(uname -m)— Returns the system architecture (e.g., x86_64, aarch64)
Post-Installation Steps
Add your user to the Docker group to run Docker without sudo:
sudo usermod -aG docker $USER
Log out and back in for group membership to take effect.
Additional Notes
- Ensure your Ubuntu version is supported (18.04, 20.04, 22.04, or later)
- Verify that hardware virtualization is enabled in BIOS/UEFI if running nested containers
- Configure Docker daemon startup on boot if needed