Skip to content

Instantly share code, notes, and snippets.

@AllieUbisse
Last active August 12, 2020 05:27
Show Gist options
  • Save AllieUbisse/67af68e412e0930579714925ce09b6f4 to your computer and use it in GitHub Desktop.
Save AllieUbisse/67af68e412e0930579714925ce09b6f4 to your computer and use it in GitHub Desktop.
How to Automate Docker installation by executing a Bash script from GitHub Gist πŸ“–
#!/bin/bash
##################################################################################
# ----------------------------------------------------------------
# THIS SCRIPT WILL HELP YOUR AUTOMATE THE DOCKER INSTALATION STEPS
# ----------------------------------------------------------------
# Test was ran on aws ec2 instance.
#
# AUTHOR:
# Name: Allie Silver Ubisse
# Email: [email protected]
##################################################################################
#
#
#
echo "============================================================================"
echo "( 1 of 7 ) WARNING: You are about to install docker to your machine "
echo "============================================================================"
#
sudo apt-get update
echo "========================================================================================================="
echo "( 2 of 7 ) Installing: curl apt-transport-https ca-certificates gnupg-agent software-properties-common "
echo "========================================================================================================="
sudo apt-get install \
apt-transport-https \
ca-certificates\
curl \
gnupg-agent \
software-properties-common -y &&
echo "============================================================================"
echo "( 3 of 7 ) TASK "
echo "============================================================================"
#
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - &&
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable" &&
echo "============================================================================"
echo "( 4 of 7 ) INSTALLING: docker-ce docker-ce-cli containerd.io "
echo "============================================================================"
#
sudo apt-get install docker-ce docker-ce-cli containerd.io -y &&
apt-cache madison docker-ce &&
echo "============================================================================"
echo "( 5 of 7 ) INSTALLING: docker.io "
echo "============================================================================"
#
sudo apt install docker.io -y &&
echo "============================================================================"
echo "( 6 of 7 ) INSTALLING: docker-compose "
echo "============================================================================"
#
sudo apt install docker-compose -y &&
echo "============================================================================"
echo "( 7 of 7 ) Thank you!, Report any bugs and star the gist "
echo "============================================================================"
#
@AllieUbisse
Copy link
Author

AllieUbisse commented Aug 10, 2020

πŸ“š HOW TO USE THE SCRIPT πŸ“š


πŸ“– Do not forget to star ⭐ the gist so it can help a lot of people

  1. Install Curl
sudo apt install curl
  1. Run the following command to install
 bash <(curl -Ls https://gist.githubusercontent.com/AllieUbisse/67af68e412e0930579714925ce09b6f4/raw/140d0898331d2d90279169cbeb456cc10023ab64/docker_installer.sh)
  1. Test Docker by starting and checking the status
 sudo service docker start
 sudo service docker status
sudo systemctl enable docker # use sudo systemctl disable docker to undo
  1. Add user to the docker group, I could not automate adding user since you might be required to create a custom user.

    Feel free to change $USER to your custom user NB: $USER returns the name of the current login user.
 sudo usermod -a -G docker $USER 
  1. Verify changes and check if user was added NB: you might need to reboot the system if you get this Known Error πŸ› Cannot connect to the Docker daemon. Is the docker daemon running on this host? πŸ›
newgrp docker
 docker info

Verify that you can run docker commands without sudo

 docker run hello-world

πŸ› REPORT ✨ :

If you get ERROR:

WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied

To fix this problem, either remove the ~/.docker/ directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

Kindly report any bugs or additional features due to script

πŸ† credits:

πŸ“Ή @soumilshah1995 youtube channel πŸ₯‡

πŸ› @Jens Answer on StackOverFlow ubuntu 20.x bug fix πŸ₯‡

πŸ’― Docker docs

πŸ‘ Create a docker image AWS EC2

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