Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EvgenyOrekhov/1ed8a4466efd0a59d73a11d753c0167b to your computer and use it in GitHub Desktop.
Save EvgenyOrekhov/1ed8a4466efd0a59d73a11d753c0167b to your computer and use it in GitHub Desktop.
A simple Docker and Docker Compose install script for Ubuntu
#!/bin/sh
set -o errexit
set -o nounset
IFS=$(printf '\n\t')
# Docker
sudo apt remove --yes docker docker-engine docker.io containerd runc || true
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
sudo wget --output-document=/usr/local/bin/docker-compose "https://github.com/docker/compose/releases/download/$(wget --quiet --output-document=- https://api.github.com/repos/docker/compose/releases/latest | grep --perl-regexp --only-matching '"tag_name": "\K.*?(?=")')/run.sh"
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'
@decentraliser
Copy link

The link to run.sh seems broken

--2021-12-19 11:45:04--  https://github.com/docker/compose/releases/download/v2.2.2/run.sh
Resolving github.com (github.com)... 140.82.121.3
Connecting to github.com (github.com)|140.82.121.3|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2021-12-19 11:45:04 ERROR 404: Not Found.

@SirMorfield
Copy link

@decentraliser yes the link is broken, since the 2.x rework in GoLang the auto completion script was removed
I suggest we remove the auto completion install form the script

Reference:
docker/docs#14692 (comment)
docker/cli#3429 (review)

@mricim
Copy link

mricim commented May 9, 2023

#!/bin/sh

set -o errexit
set -o nounset
IFS=$(printf '\n\t')

# Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
printf '\nDocker installed successfully\n\n'

printf 'Waiting for Docker to start...\n\n'
sleep 5

# Docker Compose
COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep 'tag_name' | cut -d\" -f4)
sudo curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo curl -L https://raw.githubusercontent.com/docker/compose/${COMPOSE_VERSION}/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
printf '\nDocker Compose installed successfully\n\n'
sudo docker-compose -v

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