3.2 KiB
title, source, author, published, created, description, tags
| title | source | author | published | created | description | tags | ||
|---|---|---|---|---|---|---|---|---|
| shenwei |
|
#docker #ubuntu
Installing Docker and Docker Compose on Ubuntu involves a few straightforward steps. It's generally best to install from Docker's official repositories to ensure you have the latest version.
🐋 Step 1: Uninstall Old Versions (If Applicable)
First, remove any existing, potentially conflicting Docker packages:
Bash
for pkg in docker.io docker-engine docker-ce docker.io docker-compose docker-compose-v2; do sudo apt-get remove $pkg; done
🛠️ Step 2: Set Up Docker's Repository
You need to set up the repository to allow apt to use a repository over HTTPS:
-
Update the
aptpackage index:Bash
sudo apt-get update -
Install necessary packages:
Bash
sudo apt-get install ca-certificates curl -
Add Docker's official GPG key:
Bash
sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc -
Add the repository to
aptsources:Bash
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
🚀 Step 3: Install Docker Engine
Now that the repository is set up, you can install the Docker Engine packages:
-
Update the
aptpackage index again:Bash
sudo apt-get update -
Install the Docker packages:
Bash
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin(Note: The
docker-compose-plugininstalls Docker Compose V2, which is used via the commanddocker composeinstead ofdocker-compose).
✅ Step 4: Verify the Installation
Check that the Docker Engine is running and that the installation was successful by running the test image:
Bash
sudo docker run hello-world
If successful, this command downloads a test image and runs it, printing an informational message before exiting.
👤 Step 5: Manage Docker as a Non-Root User (Recommended)
By default, running Docker commands requires sudo. To run Docker without sudo, you can add your user to the docker group:
-
Add your user to the
dockergroup:Bash
sudo usermod -aG docker $USER -
Log out and log back in (or restart your terminal session, or run
newgrp docker) for the changes to take effect. -
Verify without
sudo:Bash
docker run hello-world
You should now have Docker Engine and Docker Compose (V2) installed and ready to use!
Would you like to know some basic Docker commands or learn how to write a simple docker-compose.yml file?