Created
September 19, 2025 00:28
-
-
Save rowland007/04fbdaf7aa286371b8584aacd3143beb to your computer and use it in GitHub Desktop.
Ubuntu Docker Install
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 | |
# Function to check if the script is running as root | |
check_root() { | |
if [ "$EUID" -ne 0 ]; then | |
echo "Please run as root or use sudo." | |
exit 1 | |
fi | |
} | |
# Function to execute commands and echo status | |
execute_command() { | |
echo "Executing: $1" | |
eval "$1" | |
if [ $? -ne 0 ]; then | |
echo "Error occurred while executing: $1" | |
exit 1 | |
fi | |
} | |
# Check if the script is running as root | |
check_root | |
# Update and upgrade packages | |
execute_command "apt update && apt upgrade -y" | |
execute_command "apt autoclean -y" | |
execute_command "apt autoremove -y" | |
# Install required packages | |
execute_command "apt install -y curl ca-certificates wget" | |
# Create keyrings directory | |
execute_command "install -m 0755 -d /etc/apt/keyrings" | |
# Download Docker GPG key | |
execute_command "curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc" | |
# Set permissions for the GPG key | |
execute_command "chmod a+r /etc/apt/keyrings/docker.asc" | |
# Add Docker repository to apt | |
execute_command "echo \"deb [arch=\$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \$(. /etc/os-release && echo \"\${UBUNTU_CODENAME:-\$VERSION_CODENAME}\") stable\" | tee /etc/apt/sources.list.d/docker.list > /dev/null" | |
# Install Docker packages | |
execute_command "apt update && apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin" | |
execute_command "apt upgrade -y" | |
execute_command "apt autoclean -y" | |
execute_command "apt autoremove -y" | |
# Test Docker installation | |
execute_command "docker run hello-world" | |
echo "Script completed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment