#!/bin/bash # # Installs Docker Engine with the Buildx and Compose plugins on Ubuntu, # following https://docs.docker.com/engine/install/ubuntu/ # # Usage: curl -fsSL | bash - set -euo pipefail # bash runs a piped script line by line as it arrives, and a command that # reads stdin reads the lines not yet run. main is called only once the # whole file has been read. main() { if [ "$(id -u)" -eq 0 ]; then sudo="" else sudo="sudo" fi # Ubuntu derivatives such as Linux Mint list ubuntu in ID_LIKE and set # UBUNTU_CODENAME to the release they are based on. local codename codename="$( . /etc/os-release case " ${ID:-} ${ID_LIKE:-} " in *" ubuntu "*) echo "${UBUNTU_CODENAME:-${VERSION_CODENAME:-}}" ;; esac )" || codename="" if [ -z "$codename" ]; then echo "This script installs Docker on Ubuntu, and /etc/os-release names no Ubuntu release." >&2 exit 1 fi echo "Installing docker..." # A host set up with the one-line format has docker.list, which would list # the repository a second time. If its key is gone, apt-get update fails. $sudo rm -f /etc/apt/sources.list.d/docker.list # Add Docker's official GPG key: $sudo apt-get update $sudo apt-get install -y ca-certificates curl $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: $sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null <