Last active
October 31, 2024 13:18
-
-
Save mmaous/1536195255a41b6989e1e0faf014b6b1 to your computer and use it in GitHub Desktop.
Install Docker on a Ubuntu and configure Docker to run without sudo
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 | |
echo "Updating package index..." | |
sudo apt-get update | |
echo "Installing required packages..." | |
sudo apt-get install -y ca-certificates curl | |
echo "Setting up Docker's GPG key..." | |
sudo install -m 0755 -d /etc/apt/keyrings | |
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc | |
sudo chmod a+r /etc/apt/keyrings/docker.asc | |
echo "Adding Docker repository to APT sources..." | |
echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ | |
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
echo "Updating package index again..." | |
sudo apt-get update | |
echo "Installing Docker packages..." | |
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
echo "Verifying Docker installation..." | |
sudo docker run hello-world | |
echo "Docker installation completed successfully!" | |
# Step 2: Allowing Docker to be run without sudo (Optional) | |
# Add the current user to the docker group | |
sudo usermod -aG docker $USER | |
# Apply the new group membership | |
sudo su - $USER | |
# Confirm group membership | |
id -nG | |
# install docker compose | |
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} | |
mkdir -p $DOCKER_CONFIG/cli-plugins | |
curl -SL https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose | |
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose | |
# Provide instructions to the user | |
echo "Docker & Docker Compose is now installed and configured to run without sudo." | |
echo "Please log out and back in or restart your system for the changes to take effect." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment