Skip to content

Instantly share code, notes, and snippets.

@jay-w-opus
Last active September 20, 2022 12:33
Show Gist options
  • Save jay-w-opus/a7f2a052e7d82530aeb34841c10acf3c to your computer and use it in GitHub Desktop.
Save jay-w-opus/a7f2a052e7d82530aeb34841c10acf3c to your computer and use it in GitHub Desktop.
Install Docker with script, with region mirrors
#!/usr/bin/env bash
sudo -v
# for ARM
repo=ubuntu
if [[ $(uname -p) == 'arm' ]]
then
repo=ubuntu_ports
fi
ping google.com -W0.5 -c1
no_google=$?
if [[ $no_google > 0 ]];
then
apt_host=mirrors.tuna.tsinghua.edu.cn
codename=$(lsb_release -c -s)
sudo tee /etc/apt/sources.list > /dev/null << EOF
deb https://${apt_host}/${repo}/ ${codename} main restricted universe multiverse
deb https://${apt_host}/${repo}/ ${codename}-updates main restricted universe multiverse
deb https://${apt_host}/${repo}/ ${codename}-backports main restricted universe multiverse
deb https://${apt_host}/${repo}/ ${codename}-security main restricted universe multiverse
EOF
fi
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt-get install -y apt-transport-https \
ca-certificates gnupg-agent \
software-properties-common curl
sudo mkdir -p /etc/apt/keyrings
if [[ $no_google ]]
then
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/aliyun.docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/aliyun.docker.gpg] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
else
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
fi
sudo apt update
sudo apt install -y docker-ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment