Skip to content

Instantly share code, notes, and snippets.

@adamz01h
Last active April 1, 2025 01:23
Show Gist options
  • Select an option

  • Save adamz01h/4937d9ceab1ea36e0b5d7d114f7e134d to your computer and use it in GitHub Desktop.

Select an option

Save adamz01h/4937d9ceab1ea36e0b5d7d114f7e134d to your computer and use it in GitHub Desktop.
install_docker.sh
echo "installing docker..."
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl -y
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:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] 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 update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
#start docker service
sudo systemctl start docker
# Replace "desired_group" with the group you want to check
desired_group="docker"
# Get the current user
current_user=$(whoami)
# Check if the user is in the desired group
if id -nG "$current_user" | grep -qw "$desired_group"; then
echo "User $current_user is a member of group $desired_group."
else
echo "User $current_user is NOT a member of group $desired_group."
echo "Adding $USER to docker group you will need to reboot to apply changes."
echo "Run this script again to continue after reboot"
sudo usermod -aG docker $USER
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment