Introduction
Containerization has revolutionized application deployment and management, offering unparalleled consistency and efficiency. Docker stands at the forefront of this technology, allowing you to package applications into portable containers. Docker Compose, its indispensable companion, simplifies the management of multi-container Docker applications. This guide will walk you through installing both Docker and Docker Compose on your Ubuntu 24.04 system, setting you up for modern development and deployment workflows.
Prerequisites
Before proceeding, ensure you have:
- An Ubuntu 24.04 server with a non-root sudo user. If you haven’t set this up yet, follow our guide on How to Create a Sudo User on Ubuntu 24.04.
- Basic familiarity with the Linux command line. Check out Mastering Your Ubuntu 24.04 Server: A Comprehensive Setup Guide if you’re new to server administration.
Step 1: Update System and Install Dependencies
First, it’s good practice to update your package index and install necessary dependencies:
sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release -y
Step 2: Add Docker’s Official GPG Key
Next, add Docker’s official GPG key to ensure the packages you install are authentic:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Step 3: Add Docker Repository
Now, add the Docker repository to your 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
Step 4: Install Docker Engine and Docker Compose
Update the package index again to include the new Docker repository:
sudo apt update
Now you can install Docker Engine, Containerd, and Docker Compose:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Step 5: Verify Docker Installation
Verify the Docker installation by running the hello-world container:
sudo docker run hello-world
If successful, you’ll see a message indicating that your Docker installation is working correctly.
Step 6: Run Docker Without Sudo (Optional)
To avoid using sudo every time you run Docker commands, add your user to the docker group:
sudo usermod -aG docker $USER
newgrp docker
Log out and log back in, or simply run newgrp docker to apply the group changes without logging out. After this, you should be able to run Docker commands without sudo. Test it again:
docker run hello-world
Step 7: Enable Docker to Start on Boot
To ensure Docker starts automatically when your server boots:
sudo systemctl enable docker
sudo systemctl start docker
Troubleshooting
If you encounter issues, check the Docker service status:
sudo systemctl status docker
You can also view Docker logs for detailed error information:
sudo journalctl -u docker -n 50 --no-pager
Further Reading
Now that you have Docker and Docker Compose installed, you might want to explore:
- How to Install Coolify on Ubuntu 24.04 LTS – Self-hosted PaaS built on Docker
- Optimizing Performance: How to Set Up a Swap File on Ubuntu 24.04 – Essential for container-heavy workloads
- How to Use UFW (Uncomplicated Firewall) on Ubuntu – Secure your Docker host
- Setting up Nginx as a Reverse Proxy for Docker Containers – Common production setup
Conclusion
You have successfully installed Docker Engine and Docker Compose on your Ubuntu 24.04 system. You are now ready to build, run, and manage your containerized applications efficiently. For more advanced Docker usage and container orchestration, consider exploring tools like Kubernetes or Docker Swarm as your needs grow.
