Skip to content

Instantly share code, notes, and snippets.

@dwdraju
Last active October 5, 2024 14:18
Show Gist options
  • Save dwdraju/301234f2c902e506a30a01dd340589d1 to your computer and use it in GitHub Desktop.
Save dwdraju/301234f2c902e506a30a01dd340589d1 to your computer and use it in GitHub Desktop.
install docker

Install Docker and Docker Compose

Download above script

Copy link of Raw script

wget URL

Make the script executable

chmod +x ./install-docker.sh

Run the script with root permission

sudo ./install-docker.sh
#!/bin/sh
set -o errexit
set -o nounset
IFS=$(printf '\n\t')
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl -y
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 Apt sources:
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
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
sudo usermod -aG docker "ubuntu"
sudo systemctl enable docker
printf '\nDocker installed successfully\n\n'
printf 'Waiting for Docker to start...\n\n'
sleep 5
if ! docker info > /dev/null 2>&1; then
echo "Docker process isn't running - please start docker and try again!"
exit 1
fi
# Docker Compose
COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
sudo curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo su - "ubuntu"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment