Skip to content

Instantly share code, notes, and snippets.

@dabumana
Last active April 4, 2025 02:22
Show Gist options
  • Save dabumana/b248f25c7452e246053da24d702599be to your computer and use it in GitHub Desktop.
Save dabumana/b248f25c7452e246053da24d702599be to your computer and use it in GitHub Desktop.
Install docker and docker-compose easily on linux.
#!/bin/bash
#
# Author: @dabumana
# Copyright BSD
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OS=$1
if [ -z "$1" ]
then
echo "Help: ./install-docker.sh [OPERATIVE SYSTEM NAME] - You are missing an argument to define OS."
exit
fi
# Update local repositories
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common libssl-dev libffi-dev git wget nano
# Create docker group
sudo groupadd docker
sudo usermod -aG docker ${USER}
# Download repository key
curl -fsSL https://download.docker.com/linux/"$OS"/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$"OS" $(lsb_release -cs) stable"
# Update new index
sudo apt-get update
# Install docker
sudo apt-get install -y docker-ce containerd.io docker-compose
sudo curl -sSL https://github.com/docker/compose/releases/download/v`curl -s https://github.com/docker/compose/tags | grep "compose/releases/tag" | sed -r 's|.*([0-9]+\.[0-9]+\.[0-9]+).*|\1|p' | head -n 1`/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose
# Start docker service
sudo service docker start
# Restart terminal
source ~/.profile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment