Docker has become an essential tool in modern software development, with 42% of professionals incorporating it into their tech stack. Its growing adoption is driven by its ability to simplify workflows, allowing developers to package applications along with their dependencies into lightweight, portable containers.
In this guide, we'll walk through how to install Docker on Ubuntu 24.04, covering different installation methods, verification steps, and essential setup commands for a successful installation.
Docker is a platform that allows you to package, distribute, and run applications in lightweight, portable containers. Unlike virtual machines, which require a full operating system for each instance, Docker containers share the host system’s kernel, making them faster and more efficient.
With Docker, your application runs consistently across different environments, whether on your local machine, a testing server, or in production. This consistency is why Docker is widely used in DevOps, cloud deployments, and CI/CD workflows.
Before getting started, make sure you have the following in place:
Once these are set up, you’re ready to install Docker.
Before installing Docker, it's important to update your system to ensure compatibility with the latest software packages. This prevents conflicts and keeps your system secure.
Run the following command to update your package index and upgrade existing packages:
sudo apt update && sudo apt upgrade -y |
Next, install essential dependencies for secure package downloads and SSL certificate verification:
sudo apt install -y curl ca-certificates |
With your system updated and dependencies installed, you're ready to install Docker.
There are two primary ways to install Docker:
This is the simplest method and ensures a stable installation, but the version may not be the latest.
To install Docker from Ubuntu’s built-in package manager, run:
sudo apt install -y docker.io |
This installs Docker along with its necessary components. However, if you need the most up-to-date features, consider installing Docker from the official repository instead.
If you want the latest version of Docker with ongoing updates, install it directly from Docker’s 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 |
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io |
Installing Docker from its official repository guarantees you’re running the latest and most secure version of Docker. Now that Docker is installed, let's verify that it's running correctly.
After installation, it's important to confirm that Docker is running correctly. Run the following command to check the installed version of Docker:
docker --version |
This should return output similar to:
If you see a version number, Docker is installed successfully.
Next, verify that the Docker service is active and running. To do this run the following command:
sudo systemctl status docker |
If Docker is running correctly, you should see:
If the status shows "active (running)", Docker is installed and running.
By default, Docker requires administrative (root) privileges, meaning you must use sudo for every command. To make Docker more convenient, you can add your user to the Docker group, allowing you to run Docker commands without sudo.
Run the following command to add your user to the Docker group:
sudo usermod -aG docker $USER |
For the changes to take effect, you must log out and log back in. Alternatively, you can apply the changes immediately with:
newgrp docker |
After re-logging in, check whether your user is now part of the Docker group by running:
groups |
If you see docker listed among the groups, your user now has the necessary permissions. At this point, you should be able to run Docker commands without sudo.
To confirm, check the Docker version:
docker version |
If the setup is correct, you should get an output similar to this:
If the Docker version appears without any permission errors, your user has been successfully added to the Docker group.
To confirm that Docker is working properly, run a test container using the hello-world image:
docker run hello-world |
If everything is set up correctly, you should get an output similar to this:
If you see the expected output, your Docker installation is complete.
To ensure Docker starts automatically after a reboot, enable the service:
sudo systemctl enable docker |
This is essential if you plan to run containers that should persist across reboots.
Once Docker is installed and running, it’s essential to understand the core commands used to work with Docker images and containers.
Docker provides a built-in help system to explore available commands.
To list all available Docker commands, run:
docker |
To get detailed help on a specific command, use:
docker <command> --help |
For example, to learn more about the run command:
docker run --help |
This will display usage instructions and available options for the run command, helping you understand how to use it effectively.
Docker images act as blueprints for containers. They contain everything needed to run an application, including the operating system, dependencies, and application code.
Docker Hub is the default registry where you can find official and community-built images.
To search for an image, run:
docker search nginx |
This command returns a list of images related to "nginx," along with their details. The output looks something like this:
If you're new to Docker, it's best to choose an official image, which is indicated by an [OK] in the 'Official' column. In this example, the only image marked [OK] is the one provided by Nginx.
Once you find the image you need, download it to your system using the docker pull command:
docker pull <image_name> |
For example, to download the official Nginx image, run:
docker pull nginx |
This means Docker has successfully connected to Docker Hub (Docker’s public repository for images), downloaded the requested image, and stored it locally on your system. Now, you can use this image to create and run containers without needing to download it again.
To view all images currently available on your system, run:
docker images |
The output displays the repository name, tag (version), image ID, creation date, and size.
A container is a running instance of an image. Once you have downloaded an image, you can create and run a container from it.
To create and start a container from the nginx image while exposing it on port 8080, use the following command:
docker run -d -p 8080:80 nginx |
Once the command runs successfully, you can open a web browser and visit: http://localhost:8080
If everything is set up correctly, you should see the Nginx welcome page like the one below:
To check which containers are currently running, use the following command:
docker ps |
If you want to see all containers, including those that have stopped, run:
docker ps -a |
From the output, there are two containers: the nginx container, which is currently running, and the hello-world container, which has exited. This makes it clear that nginx is still running, while hello-world has already stopped.
Once a container is no longer needed, you can stop and remove it to free up system resources.
To stop a running container, use:
docker stop <container_id> |
Replace <container_id> with the actual Container ID from docker ps.
For example, to stop the nginx container with ID 032fe3f24966, we’ll run:
docker stop 032fe3f24966 |
To check currently running containers, use:
docker ps |
Since the container is now stopped, it won’t appear in the output. However, to see all containers, including stopped ones, run:
docker ps -a |
From your previous output, this should now display:
To delete a stopped container, use:
docker rm <container_id> |
For example, to remove the nginx container, we’ll run:
docker rm 032fe3f24966 |
To remove all stopped containers at once, run:
docker rm $(docker ps -aq) |
This will delete both the nginx and hello-world containers, ensuring they no longer take up space.
If you no longer need a Docker image, you can delete it from your system. However, before removing an image, you must first delete any containers that are using it.
To remove an image, use:
docker rmi <image_name> |
For example, to remove the nginx image, run:
docker rmi nginx |
If the image is still being used by a container, you will see an error message similar to:
This means that at least one container (in this case, container a05d69559cf1) is still associated with the nginx image.
To delete the image along with any dependent containers, use the -f flag:
docker rmi -f <image_name> |
For example, to force-remove nginx:
docker rmi -f nginx |
This will delete both the image and any containers using it, resolving the conflict.
By following this guide, you’ve successfully installed Docker on Ubuntu 24.04, verified the installation, and learned essential commands for managing images and containers. With Docker running, you can now streamline application deployment, create isolated environments, and manage containerized workloads efficiently.