Last active
May 24, 2022 00:03
-
-
Save Kvanrooyen/2db194b37742b506af59772d6e064f7d to your computer and use it in GitHub Desktop.
Install Docker on an Ubuntu machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install Docker on Ubuntu # | |
#--------------------------# | |
# Update packages | |
sudo apt update | |
# Install prerequistes | |
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y | |
# Add GPG Key for the official Docker repository | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg | |
# Add Docler repo to APT sources | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
# Update packages again | |
sudo apt update | |
# Ensure that docker is being installed from Docker and not from Ubuntu | |
apt-cache policy docker-ce | |
sleep 2 | |
echo "Is Docker installed from the Docker repo? [y/n]" | |
read userInput | |
while true; do | |
if [ $userInput == "y" ] || [ $userInput == "Y"]; then | |
sudo apt install docker-ce -y | |
echo "Docker should now be active..." | |
sudo systemctl status docker | |
elif [ $userInput == "n"] || [ $userInput == "N" ]; then | |
# Some better error handling is needed | |
echo "Oh no... :( Exiting the script so that you can debug" | |
break | |
else | |
echo "Please choose: Y or N" | |
continue | |
fi | |
done | |
clear | |
echo "Do you want to run Docker without sudo?? [Y/N]" | |
read sudoYesNo | |
while true; do | |
if [ $sudoYesNo == "y"] || [ $sudoYesNo == "Y" ]; then | |
sudo usermod -aG docker ${USER} | |
su - ${USER} | |
echo "All done. You can now run docker without sudo." | |
break | |
elif [ $sudoYesNo == "n"] || [ $sudoYesNo == "N" ]; then | |
echo "No problem. Enjoy Docker :)" | |
break | |
else | |
echo "Please choose: Y or N" | |
continue | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment