sh install-docker.sh
- log out
- log back in
The script was assembled using the official Docker docs:
sh install-docker.sh
The script was assembled using the official Docker docs:
#!/bin/sh | |
set -o errexit | |
set -o nounset | |
IFS=$(printf '\n\t') | |
# Docker | |
#Checks for old packages and removes if required | |
OLD_DOCKER=("docker" "docker-engine" "docker.io" "containerd" "runc") | |
for PACKAGE in ${OLD_DOCKER[@]}; do | |
if [ -z $(dpkg-query -W -f='${Version}' $PACKAGE 2>/dev/null) ]; then | |
printf '%s not installed.\n' "$PACKAGE" || exit | |
else | |
sudo apt -qq remove --yes $PACKAGE 2>/dev/null | |
printf '%s removed.\n' "$PACKAGE" || exit | |
fi | |
done | |
sudo apt update | |
sudo apt --yes --no-install-recommends install apt-transport-https ca-certificates | |
wget --quiet --output-document=- https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository --yes "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release --codename --short) stable" | |
sudo apt update | |
sudo apt --yes --no-install-recommends install docker-ce docker-ce-cli containerd.io | |
sudo usermod --append --groups docker "$USER" | |
sudo systemctl enable docker | |
printf '\nDocker installed successfully\n\n' | |
printf 'Waiting for Docker to start...\n\n' | |
sleep 5 | |
# Docker Compose | |
compose_release() { | |
curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | | |
grep -Po '"tag_name": "\K.*?(?=")' | |
} | |
if ! [ -x "$(command -v docker-compose)" ]; then | |
sudo curl -L https://github.com/docker/compose/releases/download/$(compose_release)/docker-compose-$(uname -s)-$(uname -m) \ | |
-o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose && sudo wget --output-document=/etc/bash_completion.d/docker-compose "https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose" && printf '\nDocker Compose installed successfully\n\n' | |
fi | |
printf '\nDocker Compose installed successfully\n\n' |