Last active
December 13, 2022 19:54
-
-
Save stiwardjherikofcr/f99bfe3ee32fe2927e7d2cf0447a6b5f to your computer and use it in GitHub Desktop.
Install Latest or Specific Version of Docker in Ubuntu 22.04|20.04|18.04 LTS
This file contains hidden or 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 | |
| # $1: version of Docker Engine to install | |
| # update the apt package index | |
| sudo apt update | |
| # install packages to allow apt to use a repository over HTTPS | |
| sudo apt install -y \ | |
| apt-transport-https \ | |
| ca-certificates \ | |
| curl \ | |
| gnupg-agent \ | |
| software-properties-common \ | |
| lsb-release | |
| # add Docker’s official GPG key | |
| curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
| # set up the stable repository | |
| sudo add-apt-repository \ | |
| "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu \ | |
| $(lsb_release -cs) \ | |
| stable" | |
| # update the apt package index | |
| sudo apt update | |
| # install the latest version of Docker Engine or a specific version | |
| if [ -z "$1" ]; then | |
| sudo apt install -y docker-ce docker-ce-cli containerd.io | |
| else | |
| sudo apt install -y docker-ce=$1 docker-ce-cli=$1 containerd.io | |
| fi | |
| # verify that Docker Engine is installed correctly | |
| sudo systemctl status docker | |
| # add the user to the docker group | |
| sudo usermod -aG docker ${USER} | |
| # log out and log back in so that your group membership is re-evaluated | |
| su - ${USER} | |
| # verify that you can run docker commands without sudo | |
| id -nG | |
| # Verify the Docker Engine version | |
| docker -v | |
| # chmod +x install_docker_ubuntu.sh | |
| # ./install_docker_ubuntu.sh <version> or ./install_docker_ubuntu.sh | |
| # Example: ./install_docker_ubuntu.sh or ./install_docker_ubuntu.sh 5:19.03.8~3-0~ubuntu-focal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment