Created
December 6, 2023 22:43
-
-
Save CalebBarnes/1cebffedda280138e6c4e6a5911310ab to your computer and use it in GitHub Desktop.
Setup Docker on Ubuntu Server
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
echo -e '\u001B[32m'Setting up Docker!'\033[0m' | |
# Add Docker's official GPG key: | |
sudo apt-get update | |
sudo apt-get install ca-certificates curl gnupg | |
sudo install -m 0755 -d /etc/apt/keyrings | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor | sudo tee /etc/apt/keyrings/docker.gpg > /dev/null | |
sudo chmod a+r /etc/apt/keyrings/docker.gpg | |
echo Adding the docker repository to Apt sources: | |
# Add the repository to Apt sources: | |
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 | |
sudo apt-get update | |
echo -e '\u001B[32m'Installing the latest Docker packages:'\033[0m' | |
# Install the latest Docker packages. | |
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y | |
echo -e '\u001B[32m'Testing docker run with sudo:'\033[0m' | |
# Verify that the Docker Engine installation is successful by running the hello-world image. | |
sudo docker run hello-world | |
# The docker group grants root-level privileges to the user. For details on how this impacts security in your system, see Docker Daemon Attack Surface. | |
# Create the docker group. | |
if ! getent group docker > /dev/null 2>&1; then | |
echo -e '\u001B[32m'Adding group "docker"'\033[0m' | |
sudo groupadd docker | |
fi | |
echo -e '\u001B[32m'Adding $USER to group "docker"'\033[0m' | |
# Add your user to the docker group. | |
sudo usermod -aG docker $USER | |
echo -e '\u001B[32m'Finished setting up Docker!'\033[0m' | |
echo -e '\u001B[32m'Activating changes to groups. | |
echo -e '\033[0m'Try the command '\u001B[34m'"docker run hello-world"'\033[0m' | |
echo -e to verify that docker is working without sudo command. | |
echo -e '\033[0m'If not, try logging out and back in again.'\033[0m' | |
# run the following command to activate the changes to groups | |
newgrp docker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Paste this command in the terminal to run the whole gist:
/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/CalebBarnes/1cebffedda280138e6c4e6a5911310ab/raw/45251744edd379ce43fde75a6bec62e23b1e67b2/setup-docker.sh)"