Catch Hackers in Action: Set Up T-Pot Honeypot on Ubuntu Like a Pro!

Quick Installation of Docker and Docker Compose on Ubuntu Server 24.04 LTS

Overview

This script automates the installation of Docker and Docker Compose on an Ubuntu Server 24.04 LTS system. It ensures that the latest stable versions of Docker components are installed and configured properly. The script is designed to simplify the process by handling repository setup, key management, and user permissions automatically.

Why Use This Script?

Manually installing Docker requires multiple steps, including adding repositories, setting up GPG keys, and handling permissions. This script streamlines the process by:

  • Installing necessary dependencies
  • Adding Docker’s official repository
  • Installing the latest Docker Engine and CLI tools
  • Setting up user permissions
  • Installing the latest version of Docker Compose
  • Verifying the installation

By running a single script, you save time and reduce the chances of misconfiguring your Docker setup.

Script Breakdown

The script consists of several steps, each crucial for setting up Docker and Docker Compose correctly.

1. Update Package Index and Install Prerequisites

echo "Updating package index and installing prerequisites..."
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release

These commands ensure that the system has the necessary packages to securely add and manage external repositories.

2. Add Docker’s Official GPG Key and Repository

echo "Adding Docker's official GPG key and setting up repository..."
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

This section ensures that Docker’s repository is added securely, enabling the system to fetch the latest Docker packages.

3. Install Docker Engine

echo "Installing Docker Engine..."
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin

This step installs the Docker Engine and related components required for running containers.

4. Add Current User to the Docker Group

echo "Adding current user to the Docker group..."
sudo usermod -aG docker $USER

This step allows the current user to run Docker commands without needing sudo. However, changes take effect only after logging out and back in.

5. Install Docker Compose

echo "Installing Docker Compose..."
DOCKER_COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
sudo curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

This section fetches the latest version of Docker Compose directly from GitHub and makes it executable.

6. Verify Installation

echo "Verifying Docker installation..."
docker --version
echo "Verifying Docker Compose installation..."
docker-compose --version

These commands confirm that Docker and Docker Compose were installed correctly and display their versions.

7. Final Message

echo "Docker and Docker Compose installation completed successfully!"
echo "You need to log out and back in for group changes to take effect."

This message reminds the user to log out and back in so that the docker group changes take effect.

How to Use the Script

To run this script on your Ubuntu Server 24.04 LTS:

  1. Download install-docker.sh
    install-docker.sh
  2. Make the script executable:
    chmod +x install-docker.sh
  3. Run the script:
    ./install-docker.sh

Once the script completes, log out and log back in to ensure you can run Docker commands without sudo.

Conclusion

This script provides a quick and efficient way to set up Docker and Docker Compose on Ubuntu Server 24.04 LTS. By automating the installation process, it ensures consistency and reduces the chances of manual errors. If you frequently deploy containers, this script is a great tool to have in your toolkit.

Related Post

Leave a Reply