Docker is one of the most popular technologies in the modern infrastructure universe, allowing the creation and execution of containers in a lightweight, fast, and secure manner. In this article, we will clearly and objectively cover how to install Docker on Ubuntu Server 24.04 LTS and how to launch your first container. This guide is ideal for system administrators, developers, and enthusiasts who want to start working in Docker environments.
Prerequisites
Before starting, make sure you have:
- A server with Ubuntu Server 24.04 LTS installed;
- Root access or a user with sudo privileges;
- An active internet connection.
Step 1: Update the System
Before any installation, it is always recommended to update the system packages.
sudo apt update && sudo apt upgrade -y
This command updates the package list and applies available updates to the system.
Step 2: Install Docker Dependencies
Install the packages that allow APT to use repositories via HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg -y
This command installs essential packages to add HTTPS repositories and manage GPG keys.
Step 3: Add the Official Docker Repository
Add the official Docker GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker.gpg
This command downloads and stores Docker’s GPG key to ensure the authenticity of the packages.
Next, add the repository to the APT sources list:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
This command adds the official Docker repository to the APT sources list.
Update the APT cache:
sudo apt update
This command reloads the package list, now including the Docker repository.
Step 4: Install Docker Engine
Now that the repository has been added, install Docker:
sudo apt install docker-ce docker-ce-cli containerd.io -y
This command installs Docker Engine, the Docker CLI, and the containerd runtime.
Check if the service is active:
sudo systemctl status docker
This command checks if the Docker service is active and running.
If everything is correct, you will see Docker running as an active service.
Step 5: Run Docker without sudo (optional but recommended)
To run Docker commands without needing sudo
, add your user to the docker
group:
sudo usermod -aG docker $USER
This command adds your user to the Docker group, allowing you to run commands without sudo
.
You will need to log out and log back in or restart the system to apply the change.
Step 6: Test the Installation with a Container
Let’s test by launching a simple container using the hello-world
image:
docker run hello-world
This command runs a test container that prints a message, confirming that Docker is working correctly.
If the installation is correct, you will see a message confirming that Docker is working.
Step 7: Launch a Real Container (Example with Nginx)
Now let’s launch a real container, such as Nginx, a lightweight and powerful web server:
docker run -d -p 80:80 --name nginx-container nginx
This command runs an Nginx container in the background, mapping the host’s port 80 and naming the container:
-d
: runs the container in the background;
-p 80:80
: maps the host’s port 80 to the container’s port 80;
--name
: sets a custom name for the container.
To check if it is running:
docker ps
This command lists the running containers.
And to test, access your server’s IP via a browser. If everything is correct, you will see the default Nginx page.
Conclusion
With Docker installed and your first container running, you are now ready to explore the power of containers on Ubuntu Server 24.04. From here, you can create your own images, set up complete development environments, or even orchestrate multiple containers with tools like Docker Compose or Kubernetes.
Keeping up to date with best practices for security, versioning, and container organization is essential for production environments. Continue exploring and building modern and scalable solutions with Docker.
If you want to see more tutorials like this, or learn more about the extensive world of IT, follow the master of the web on our blog or on our networks like YouTube, Facebook, and Instagram to see more posts like this!