Skip to content

Instantly share code, notes, and snippets.

@locnnil
Last active July 19, 2023 23:45
Show Gist options
  • Save locnnil/7d5453c502d5a87529dd291bc43d1aaa to your computer and use it in GitHub Desktop.
Save locnnil/7d5453c502d5a87529dd291bc43d1aaa to your computer and use it in GitHub Desktop.
Install docker on server
#!/bin/bash
## This is a simple script to update
## all packages of a server and
## install docker all in one shot.
## Enjoy! :D
sudo apt-get update && sudo apt-get upgrade -y
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] 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 -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
group_name="docker"
if ! grep -q "^$group_name:" /etc/group; then
sudo groupadd docker
fi
sudo usermod -aG docker $USER
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment