Last active
July 3, 2025 23:07
-
-
Save alexolinux/bf05eca5e9fb0a9f3d08827b020bac33 to your computer and use it in GitHub Desktop.
Docker community edition installation on Linux
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 script is run as root | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root. Please use sudo." | |
exit 1 | |
fi | |
# Update package index | |
if command -v apt-get &> /dev/null; then | |
apt-get update | |
elif command -v yum &> /dev/null; then | |
yum makecache | |
else | |
echo "Unsupported package manager. Exiting." | |
exit 1 | |
fi | |
# Install required dependencies | |
if command -v apt-get &> /dev/null; then | |
apt-get install -y apt-transport-https ca-certificates curl software-properties-common | |
elif command -v yum &> /dev/null; then | |
yum install -y yum-utils device-mapper-persistent-data | |
else | |
echo "Unsupported package manager. Exiting." | |
exit 1 | |
fi | |
# Add Docker repository | |
if command -v add-apt-repository &> /dev/null; then | |
add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
# Add Docker GPG key | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - | |
elif command -v yum-config-manager &> /dev/null; then | |
yum-config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo | |
# Add Docker GPG key for CentOS | |
rpm --import https://download.docker.com/linux/centos/gpg | |
else | |
echo "Unsupported package manager. Exiting." | |
exit 1 | |
fi | |
# Install Docker CE | |
if command -v apt-get &> /dev/null; then | |
apt-get update | |
apt-get install -y docker-ce docker-ce-cli containerd.io | |
elif command -v yum &> /dev/null; then | |
yum install -y docker-ce docker-ce-cli containerd.io | |
else | |
echo "Unsupported package manager. Exiting." | |
exit 1 | |
fi | |
# Add User to Docker group | |
if [ -n "$SUDO_USER" ]; then | |
usermod -aG docker "$SUDO_USER" | |
else | |
echo "Could not determine user to add to Docker group." | |
fi | |
# Enable and start Docker service | |
if command -v systemctl &> /dev/null; then | |
systemctl enable docker && systemctl start docker | |
elif command -v service &> /dev/null; then | |
service docker start | |
else | |
echo "Unsupported service management tool. You may need to start Docker manually." | |
fi | |
echo "Docker CE has been successfully installed and started." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Docker Easy Installation for Raspberry PI