Docker has become the standard platform for building, shipping, and running applications in containers. Whether you’re a developer testing applications, a DevOps engineer managing deployments, or a system administrator hosting multiple services, Docker simplifies application deployment by packaging everything an application needs into a lightweight container.
Ubuntu 24.04 LTS is one of the most popular Linux distributions for servers, making it an excellent choice for running Docker. Combined with Docker Compose, you can easily manage multi-container applications such as WordPress, MySQL, Redis, Nginx, and many other services with a single configuration file.
In this guide, you’ll learn how to install Docker Engine and Docker Compose on Ubuntu 24.04, verify the installation, run your first container, and perform basic Docker management tasks.
Why Use Docker?
Docker offers several advantages over traditional application deployment methods:
- Fast and lightweight containers
- Consistent environments across development and production
- Easy application deployment
- Simplified dependency management
- Better resource utilization than virtual machines
- Improved scalability and portability
What is Docker Compose?
Docker Compose is a tool that allows you to define and manage multiple Docker containers using a single YAML configuration file. Instead of running several lengthy Docker commands, you can start or stop an entire application stack with one command.
For example, a web application may require:
- Nginx
- PHP
- MySQL
- Redis
Docker Compose manages all these services together.
Prerequisites
Before installing Docker, ensure that:
- Ubuntu 24.04 LTS is installed.
- You have a user account with sudo privileges.
- Your system has an active internet connection.
- The package list is up to date.
Step 1: Update Your System
Begin by updating the package index and upgrading installed packages.
sudo apt update
sudo apt upgrade -y
Keeping your system updated ensures compatibility with the latest Docker packages and security patches.
Step 2: Install Required Packages
Install the packages required to securely download Docker from the official repository.
sudo apt install ca-certificates curl gnupg lsb-release -y
These utilities allow Ubuntu to verify package signatures and communicate securely with external repositories.
Step 3: Add Docker’s Official Repository
Instead of installing Docker from Ubuntu’s default repository, use Docker’s official repository to receive the latest stable version.
Create a directory for Docker’s GPG key, download the key, and configure the repository according to Docker’s official installation instructions for Ubuntu 24.04.
After updating the package list, Ubuntu will recognize Docker packages from the official source.
Step 4: Install Docker Engine
Install Docker Engine along with its command-line tools.
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
The installation includes:
- Docker Engine
- Docker CLI
- Container Runtime
- Buildx
- Docker Compose Plugin
Step 5: Verify Docker Installation
Check whether Docker is installed correctly.
docker --version
You should see the installed Docker version displayed.
Next, verify that the Docker service is running.
sudo systemctl status docker
If the service is active, Docker is ready to use.
Step 6: Enable Docker at Boot
To ensure Docker starts automatically whenever the server reboots, enable the service.
sudo systemctl enable docker
You can also start it manually if required.
sudo systemctl start docker
Step 7: Verify Docker Compose
Modern Docker installations include Docker Compose as a plugin.
Verify its installation by running:
docker compose version
If the version information appears, Docker Compose is installed successfully.
Step 8: Run Your First Docker Container
Test your Docker installation by running the official Hello World container.
sudo docker run hello-world
Docker downloads the image automatically, creates a container, executes it, and displays a success message.
This confirms that Docker is functioning correctly.
Step 9: Allow Docker Without sudo
By default, Docker commands require sudo privileges.
Add your user to the Docker group.
sudo usermod -aG docker $USER
Log out and log back in to apply the changes.
Now you can execute Docker commands without using sudo.
Example:
docker ps
Step 10: Download a Docker Image
Docker images are stored in Docker Hub.
Download the latest Ubuntu image.
docker pull ubuntu
View downloaded images.
docker images
Step 11: Run an Interactive Container
Launch an Ubuntu container.
docker run -it ubuntu bash
Inside the container, execute Linux commands as usual.
Exit the container by typing:
exit
Step 12: Create Your First Docker Compose Project
Create a project directory.
mkdir docker-demo
cd docker-demo
Create a file named:
compose.yaml
Add the following configuration:
services:
web:
image: nginx:latest
ports:
- "8080:80"
Save the file.
Start the application.
docker compose up -d
Open your browser and visit:
http://YOUR_SERVER_IP:8080
You should see the default Nginx welcome page.
Managing Docker Compose
Stop containers.
docker compose stop
Start containers.
docker compose start
Restart containers.
docker compose restart
View logs.
docker compose logs
Remove containers.
docker compose down
Useful Docker Commands
List running containers.
docker ps
List all containers.
docker ps -a
List images.
docker images
Remove a container.
docker rm CONTAINER_ID
Remove an image.
docker rmi IMAGE_ID
Stop a container.
docker stop CONTAINER_ID
Start a stopped container.
docker start CONTAINER_ID
View Docker system information.
docker info
Common Troubleshooting
Docker service is not running
Start Docker manually.
sudo systemctl start docker
Permission denied while running Docker
Ensure your user belongs to the Docker group.
groups
If not, add your user and log in again.
Port already in use
Another application may already be using the requested port.
Identify the process using the port and either stop it or choose a different port in your Docker configuration.
Docker image download fails
Check your internet connection, firewall settings, and repository configuration.
Best Practices
- Always install Docker from the official repository.
- Keep Docker and Ubuntu updated.
- Use official container images whenever possible.
- Remove unused images and containers regularly.
- Use Docker Compose for multi-container applications.
- Store persistent data in Docker volumes.
- Avoid running containers as the root user when possible.
- Back up important Docker volumes before upgrades.
Frequently Asked Questions
Is Docker free to use?
Yes. Docker Engine is open source and free for personal use and many development scenarios.
Does Ubuntu 24.04 support Docker?
Yes. Ubuntu 24.04 LTS is fully supported by Docker and is a popular choice for production servers.
What is the difference between Docker and Docker Compose?
Docker manages individual containers, while Docker Compose manages multiple related containers using a single configuration file.
Can I install Docker without Docker Compose?
Yes. Docker Engine works independently, but Docker Compose greatly simplifies managing applications with multiple services.
Conclusion
Installing Docker and Docker Compose on Ubuntu 24.04 provides a modern, efficient platform for deploying and managing applications. With Docker, you can package software into portable containers that run consistently across different environments, while Docker Compose simplifies multi-service deployments through a single configuration file.
Whether you’re deploying web applications, databases, development environments, or self-hosted services, Docker helps streamline operations and improves consistency. By following the steps in this guide, you’ll have a fully functional Docker environment ready for development, testing, or production workloads.