BASH Function to Install Docker


The following BASH script/function tries to install the latest version of the Docker via the get.docker.com site, if you have already installed docker, it will try to update it – however you should re-login to docker and re-connect to SSH afterwards.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
 
install_docker() {
    sudo apt update
    # curl/git used by docker
    sudo apt install -y curl git
    curl https://get.docker.com | sh
    if [ "$EUID" -ne 0 ]; then 
        echo "You need 'docker login' and 'service ssh restart' again" 
        echo "for docker to function correctly"
        echo "Adding user $(whoami) to docker group"
        sudo usermod -aG docker $(whoami)
    fi
}
 
install_docker
#!/bin/bash

install_docker() {
    sudo apt update
    # curl/git used by docker
    sudo apt install -y curl git
    curl https://get.docker.com | sh
    if [ "$EUID" -ne 0 ]; then 
        echo "You need 'docker login' and 'service ssh restart' again" 
        echo "for docker to function correctly"
        echo "Adding user $(whoami) to docker group"
        sudo usermod -aG docker $(whoami)
    fi
}

install_docker

To install docker, you would also need to install some dependencies such as: curl and git.

BASH Programming/Shell

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
236 words
Last Post: Teaching Kids Programming - Back Tracking Algorithm to Generate Parentheses
Next Post: Teaching Kids Programming - Breadth First Search Algorithm to Compute the Max Width of a Binary Tree

The Permanent URL is: BASH Function to Install Docker

Leave a Reply