Created
November 4, 2023 14:21
-
-
Save welel/f80c96482e3b539487b9fa08bfcab86d to your computer and use it in GitHub Desktop.
Install Docker (with Docker Compose) on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run the following command to uninstall all conflicting packages: | |
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done | |
# Add Docker's official GPG key: | |
sudo apt-get update | |
sudo apt-get install ca-certificates curl gnupg | |
sudo install -m 0755 -d /etc/apt/keyrings | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
sudo chmod a+r /etc/apt/keyrings/docker.gpg | |
# Add the repository to Apt sources: | |
echo \ | |
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | |
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get update | |
# To install the latest version, run: | |
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
echo 'Docker successfully installed.' |
Understanding the Script
Here's a breakdown of what the script does:
- The script starts by removing any old Docker packages that might conflict with the new installation.
- It then installs necessary prerequisites like
ca-certificates
,curl
, andgnupg
to ensure secure communication with Docker’s repositories. - The Docker GPG key is added for security purposes, ensuring that all downloaded packages are verified and trusted.
- The official Docker repository is added to your system's list of sources, which guarantees that you get the latest official Docker packages.
- After updating your package index, the script installs the Docker engine (
docker-ce
), the command-line interface (docker-ce-cli
), the container runtime (containerd.io
), and the latest plugins for buildx and compose. - Finally, the script prints a success message.
Script Source
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this script to install Docker on Ubuntu