Skip to content

Instantly share code, notes, and snippets.

@welel
Created November 4, 2023 14:21
Show Gist options
  • Save welel/f80c96482e3b539487b9fa08bfcab86d to your computer and use it in GitHub Desktop.
Save welel/f80c96482e3b539487b9fa08bfcab86d to your computer and use it in GitHub Desktop.
Install Docker (with Docker Compose) on Ubuntu
#!/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.'
@welel
Copy link
Author

welel commented Nov 4, 2023

Use this script to install Docker on Ubuntu

  1. Download script
wget https://gist.githubusercontent.com/welel/f80c96482e3b539487b9fa08bfcab86d/raw/90bc2330924d225aef7dc3178f5926bda7daff04/install_docker.sh
  1. Give permissions
sudo chmod +x install_docker.sh
  1. Start the script
sudo ./install_docker.sh

@welel
Copy link
Author

welel commented Nov 4, 2023

Understanding the Script

Here's a breakdown of what the script does:

  1. The script starts by removing any old Docker packages that might conflict with the new installation.
  2. It then installs necessary prerequisites like ca-certificates, curl, and gnupg to ensure secure communication with Docker’s repositories.
  3. The Docker GPG key is added for security purposes, ensuring that all downloaded packages are verified and trusted.
  4. The official Docker repository is added to your system's list of sources, which guarantees that you get the latest official Docker packages.
  5. 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.
  6. Finally, the script prints a success message.

@welel
Copy link
Author

welel commented Nov 4, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment