Last active
May 15, 2025 07:36
-
-
Save snappytux/a4d168e2ab2d5574a5b514d5ff9e8961 to your computer and use it in GitHub Desktop.
First install docker in ubuntu 24.04
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 | |
# Check if running with root privileges | |
if [ "$(id -u)" -ne 0 ]; then | |
echo "Please run this script with root privileges (sudo)" | |
exit 1 | |
fi | |
# Stop script immediately if a command fails | |
set -e | |
echo "===== Starting system setup for new VM =====" | |
# Update and upgrade packages | |
echo "===== Updating and upgrading packages =====" | |
apt update && apt upgrade -y | |
# Set timezone | |
echo "===== Setting timezone =====" | |
apt install -y ntp | |
timedatectl set-timezone Asia/Bangkok | |
timedatectl | |
# Install required basic packages | |
echo "===== Installing basic packages =====" | |
apt install -y curl apt-transport-https ca-certificates software-properties-common gnupg lsb-release | |
# Remove old Docker versions if any | |
echo "===== Removing old Docker versions (if any) =====" | |
apt remove -y docker docker-engine docker.io containerd runc || true | |
# Install Docker from Docker's official repository | |
echo "===== Installing Docker from Official Repository =====" | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null | |
apt update | |
apt install -y docker-ce docker-ce-cli containerd.io | |
# Add current user to docker group | |
echo "===== Adding current user to docker group =====" | |
if [ -n "$SUDO_USER" ]; then | |
usermod -aG docker $SUDO_USER | |
echo "User $SUDO_USER has been added to the docker group" | |
else | |
echo "Please specify the username to add to the docker group:" | |
read -p "Username: " USERNAME | |
usermod -aG docker $USERNAME | |
echo "User $USERNAME has been added to the docker group" | |
fi | |
# Check Docker status | |
echo "===== Checking Docker status =====" | |
systemctl enable docker | |
systemctl start docker | |
/etc/init.d/docker status | |
echo "===== Setup completed successfully =====" | |
echo "Please log out and log back in for docker group settings to take effect" | |
echo "Or use 'newgrp docker' command to apply changes in the current session" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
set time
timedatectl set-time 10:16:00