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
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
This section ensures that Docker’s repository is added securely, enabling the system to fetch the latest Docker packages.
3. Install Docker Engine
This step installs the Docker Engine and related components required for running containers.
4. Add Current User to the Docker Group
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
This section fetches the latest version of Docker Compose directly from GitHub and makes it executable.
6. Verify Installation
These commands confirm that Docker and Docker Compose were installed correctly and display their versions.
7. Final Message
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:
- Download
install-docker.sh
install-docker.sh - Make the script executable:
- Run the script:
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.