#!/bin/bash
:: Filename: docker_install.sh
:: Modified: 2025-05-02
:: Purpose: Quick install Docker on RHEL system.
# Built with ❤️ by Cuongitl (https://infra.lecuong.info)
# Reset color
RESET='\033[0m'
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
# Update the system packages
echo -e "${YELLOW}Updating system packages...${RESET}"
sudo dnf update -y || { echo -e "${RED}Error updating system packages. Exiting.${RESET}"; exit 1; }
# Install the necessary packages
echo -e "${YELLOW}Installing necessary packages...${RESET}"
sudo dnf install -y dnf-utils || { echo -e "${RED}Error installing dnf-utils. Exiting.${RESET}"; exit 1; }
# Add the Docker repository
echo -e "${YELLOW}Adding Docker repository...${RESET}"
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo || { echo -e "${RED}Error adding Docker repository. Exiting.${RESET}"; exit 1; }
# Install Docker
echo -e "${YELLOW}Installing Docker...${RESET}"
sudo dnf install docker-ce docker-ce-cli containerd.io -y || { echo -e "${RED}Error installing Docker. Exiting.${RESET}"; exit 1; }
# Start the Docker service
echo -e "${YELLOW}Starting Docker service...${RESET}"
sudo systemctl start docker || { echo -e "${RED}Error starting Docker service. Exiting.${RESET}"; exit 1; }
# Enable the Docker service to start automatically on system boot
echo -e "${YELLOW}Enabling Docker service to start automatically on system boot...${RESET}"
sudo systemctl enable docker || { echo -e "${RED}Error enabling Docker service. Exiting.${RESET}"; exit 1; }
# Verify the Docker installation
echo -e "${YELLOW}Verifying Docker installation...${RESET}"
sudo docker --version || { echo -e "${RED}Error verifying Docker installation. Exiting.${RESET}"; exit 1; }
# Install Docker Compose
echo -e "${YELLOW}Installing Docker Compose...${RESET}"
sudo curl -L "https://github.com/docker/compose/releases/download/v2.35.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose || { echo -e "${RED}Error downloading Docker Compose. Exiting.${RESET}"; exit 1; }
sudo chmod +x /usr/local/bin/docker-compose || { echo -e "${RED}Error making Docker Compose executable. Exiting.${RESET}"; exit 1; }
# Verify the Docker Compose installation
echo -e "${YELLOW}Verifying Docker Compose installation...${RESET}"
if [ -x "/usr/local/bin/docker-compose" ]; then
echo -e "${GREEN}Docker Compose installed successfully.${RESET}"
else
echo -e "${RED}Error verifying Docker Compose installation. Exiting.${RESET}"
exit 1
fi
# (Optional) Create a symlink for easier access
echo -e "${YELLOW}Creating symlink for Docker Compose...${RESET}"
if [ ! -L "/usr/bin/docker-compose" ]; then
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose || { echo -e "${RED}Error creating symlink for Docker Compose. Exiting.${RESET}"; exit 1; }
else
echo -e "${CYAN}Symlink for Docker Compose already exists. Skipping.${RESET}"
fi
# Verify the Docker Compose version
echo -e "${YELLOW}Verifying Docker Compose version...${RESET}"
docker-compose --version || { echo -e "${RED}Error verifying Docker Compose version. Exiting.${RESET}"; exit 1; }
echo -e
https://gist.github.com/cuongitl/docker-install.sh