Posted in

How to Install Docker and Docker Compose on Ubuntu 24.04

How to Install Docker and Docker Compose on Ubuntu 24.04
How to Install Docker and Docker Compose on Ubuntu 24.04

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:

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:

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.

Zac Morgan is a DevOps engineer and system administrator with over a decade of hands-on experience managing Linux and Windows infrastructure. Passionate about automation, cloud technologies, and sharing knowledge with the tech community. When not writing tutorials or configuring servers, you can find Zac exploring new tools, contributing to open-source projects, or helping others solve complex technical challenges.

Leave a Reply

Your email address will not be published. Required fields are marked *