Skip to content

Instantly share code, notes, and snippets.

@ericwastaken
Last active December 4, 2024 20:36
Show Gist options
  • Save ericwastaken/c824ec7593ca54fe568f71b61f402ff2 to your computer and use it in GitHub Desktop.
Save ericwastaken/c824ec7593ca54fe568f71b61f402ff2 to your computer and use it in GitHub Desktop.
Install Docker Engine on RHEL8 or RHEL9
#!/bin/bash
# This script installs Docker Community Edition on RHEL 9 and performs necessary post-installation steps.
# Based on the instructions at https://docs.docker.com/engine/install/rhel/
#
# License: ATTRIBUTION-SHAREALIKE 4.0 INTERNATIONAL (https://creativecommons.org/licenses/by-sa/4.0/)
# By: Eric A. Soto, [email protected]
# Exit immediately if a command exits with a non-zero status
set -e
# Uninstall old versions if they exist
sudo yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# Set up the repository
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
# Install the latest version of Docker CE
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Post-installation steps
# Create the docker group if it doesn't exist
if ! getent group docker >/dev/null; then
sudo groupadd docker
fi
# Add the current user to the docker group
sudo usermod -aG docker $USER
# Refresh group membership for the current session
newgrp docker <<END
# Verify Docker installation without sudo
docker run hello-world
# Print Docker version to confirm everything is set up correctly
docker --version
END
echo "Docker installation and configuration complete. You can use Docker without needing to log out and back in."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment