Install docker in Linux ubuntu


#!/bin/bash

# Function to check if a command is available
command_exists() {
    command -v "$1" >/dev/null 2>&1
}

# Function to install Docker on Ubuntu
install_docker_ubuntu() {
    if command_exists docker; then
        echo "Docker is already installed. Skipping installation."
    else
        sudo apt-get update
        sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
        curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
        sudo add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
        sudo apt-get update
        sudo apt-get install -y docker-ce docker-ce-cli containerd.io
    fi
}

# Function to install Docker Compose
install_docker_compose() {
    if command_exists docker-compose; then
        echo "Docker Compose is already installed. Skipping installation."
    else
        sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
        sudo chmod +x /usr/local/bin/docker-compose
    fi
}

# Main script
echo "Checking Docker installation..."
install_docker_ubuntu

echo "Checking Docker Compose installation..."
install_docker_compose

Did you find this article useful?



  • oAuth2 Authentication

    https://dzone.com/articles/the-right-flow-for-the-job-which-oauth-20-flow-sho OAuth 2.0 is a well-adopted delegated authorization framework that is a...

  • KAFKA Use cases

    Data Streaming: Think of data as a fast-flowing river. We need a way to tap into that stream, harness its power, and direct it where it needs to ...

  • Starting a new Linux Ubuntu Server and secure it with UFW Firewall

    First, log in to the server using SSH as the root. 1.- Create a user with sudo capabilitiessudo adduser <name>sudo usermod -aG sudo <nam...

  • PostgreSQL Database Replication

    Primary Server Setup Firewalls to allow connectivity sudo ufw allow from <standbyIP> to any port <port> proto <protocol:-tcp>s...