Skip to content

Instantly share code, notes, and snippets.

@akiltipu
Last active March 9, 2024 19:30
Show Gist options
  • Save akiltipu/ecccd0383500cf37e4fb9a8c440aed3a to your computer and use it in GitHub Desktop.
Save akiltipu/ecccd0383500cf37e4fb9a8c440aed3a to your computer and use it in GitHub Desktop.
Install Docker and Docker Compose on Ubuntu server
#!/bin/bash
# Update the package list
sudo apt update
# Install required packages to allow apt to use a repository over HTTPS
sudo apt install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Add the Docker stable repository
echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update the package list again
sudo apt update
# Install the latest version of Docker
sudo apt install -y docker-ce docker-ce-cli containerd.io
# Verify that Docker is installed and running
sudo docker --version
# Allow Docker to be run without sudo (non-root users)
sudo usermod -aG docker $USER
# Activate the changes to the user's group without requiring a logout/login
newgrp docker
# Source the profile to apply changes in the current shell session
source /etc/profile
# Print a message indicating that Docker installation completed
echo "Docker installation completed."
# Installing Docker Compose
sudo curl -SL https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# Give execute permissions to Docker Compose
sudo chmod +x /usr/local/bin/docker-compose
# Verify that Docker Compose is installed
docker-compose --version
# Print a message indicating that Docker Compose installation completed
echo "Docker Compose installation completed."
@akiltipu
Copy link
Author

akiltipu commented Mar 9, 2024

To install Docker and Docker Compose on your Ubuntu server, navigate to your server environment and execute the following command by copying and pasting it:

wget https://gist.githubusercontent.com/akiltipu/ecccd0383500cf37e4fb9a8c440aed3a/raw/ddd75cfb248378fb6cd7e8e714525c04cc8a5ff9/install_docker_dockercompose.sh
chmod +x install_docker_dockercompose.sh
./install_docker_dockercompose.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment