Created
June 3, 2025 08:46
-
-
Save tichopad/eb6b846f5724969e50d3183a150f9800 to your computer and use it in GitHub Desktop.
Installs Docker + Compose, sets a docker group and a service
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 | |
# Exit immediately if a command exits with a non-zero status. | |
set -e | |
echo "π Starting Docker installation..." | |
# 1. Set up Docker's apt repository | |
echo "π§ Setting up Docker's apt repository..." | |
sudo apt-get update | |
sudo apt-get install -y ca-certificates curl gnupg | |
sudo install -m 0755 -d /etc/apt/keyrings | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
sudo chmod a+r /etc/apt/keyrings/docker.gpg | |
echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | |
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
# 2. Install Docker Engine | |
echo "βοΈ Installing Docker Engine, CLI, Containerd, Buildx, and Compose plugin..." | |
sudo apt-get update | |
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
# 3. Post-installation steps | |
echo "π§ Performing post-installation steps..." | |
# Create the docker group (if it doesn't already exist) | |
if ! getent group docker > /dev/null; then | |
sudo groupadd docker | |
echo "Created 'docker' group." | |
else | |
echo "'docker' group already exists." | |
fi | |
# Add the current user to the docker group | |
sudo usermod -aG docker $USER | |
echo "π€ Added user '$USER' to the 'docker' group. You'll need to log out and log back in for this to take effect." | |
# Configure Docker to start on boot with systemd | |
sudo systemctl enable docker.service | |
sudo systemctl enable containerd.service | |
echo "π Configured Docker to start on boot." | |
echo "β Docker installation and basic configuration complete!" | |
echo "π To use Docker without sudo, please log out and log back in, or run 'newgrp docker' in your current terminal." | |
echo "π‘ You can verify the installation by running: docker run hello-world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment