In this tutorial, we are going to explain how to install Docker on Ubuntu 24.04 OS. Docker is an open-source platform for running, developing, and shipping applications. Docker delivers the software in packages called containers. The advantage of the docker containers is that the developer can reduce the delay between the production and testing environment. Also, the applications can work efficiently in isolation and different environments. The software that hosts the containers is called Docker Engine.
Installing Docker is a straightforward process and may take up to 10 minutes. Let’s get started!
Table of Contents
Prerequisites
- A server running Ubuntu 24.04 OS
- User privileges: root or non-root user with sudo privileges
Step 1. Update the System
Before we start with the installation we need to update the system packages to their latest versions available.
sudo apt update -y && sudo apt upgrade -y
Step 2. Add Docker GPG key
First, we need to add the Docker GPG key to set up the repository later.
sudo apt-get install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
Step 3. Add Repository to APT sources
The next step is to add the docker repository to the advanced package tool sources. Execute the following command:
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Once added, update the system.
sudo apt-get update -y
Step 4. Install Docker
Now, when the GPG key and the docker repo are added, we can proceed with installing the docker packages with the command below:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 5. Manage Docker Service
After successful installation, we can enable the docker service to start on the system reboot automatically.
sudo systemctl start docker && sudo systemctl enable docker
You should get the following output:
root@host:~# sudo systemctl start docker && sudo systemctl enable docker Synchronizing state of docker.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install enable docker
To check the status of the docker service execute the following command:
sudo systemctl status docker
If the service is up and running you will get the following output:
root@host:~# sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled) Active: active (running) since Mon 2024-06-10 17:14:00 CDT; 6min ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 4115 (dockerd) Tasks: 9 Memory: 28.3M (peak: 29.7M) CPU: 879ms CGroup: /system.slice/docker.service └─4115 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Jun 10 17:13:59 host.test.vps systemd[1]: Starting docker.service - Docker Application Container Engine.. Jun 10 17:14:00 host.test.vps dockerd[4115]: time="2024-06-10T17:14:00.838489530-05:00" level=info msg="API listen on /run/docker.sock" Jun 10 17:14:00 host.test.vps systemd[1]: Started docker.service - Docker Application Container Engine.
To restart the Docker service you can use the following command:
sudo systemctl restart docker
To stop the Docker service you can use the command below:
sudo systemctl stop docker
Step 6. Create Docker Container
We have installed Docker and now let’s create the first Docker container. Since we are using Ubuntu 24.04 let’s make a Docker container with a Ubuntu image. In other words, it will be Ubuntu OS running inside of Ubuntu.
docker run -it ubuntu bash
The container will be created and you will get the following output:
root@host:~# docker run -it ubuntu bash Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu 00d679a470c4: Pull complete Digest: sha256:e3f92abc0967a6c19d0dfa2d55838833e947b9d74edbcb0113e48535ad4be12a Status: Downloaded newer image for ubuntu:latest root@55d468ed1b39:/#
As you can see now the prompt is changed: root@55d468ed1b39:/#. This means we are already inside the Docker container with Ubuntu.
You can copy the number of the container 55d468ed1b39 and use it to start the container whenever you want. Press CTRL+D to exit from the docker container prompt.
Now the container is not running. To start it execute the following command:
docker start 55d468ed1b39
To check whether the container is running you can use the following command:
docker ps
You should get the following output:
root@host:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5a8bbc397df7 ubuntu "bash" 7 minutes ago Up 3 minutes dreamy_chaplygin
To enter the Docker container you can use the command below:
docker exec -it 5a8bbc397df7 bash
The prompt will change to:
docker exec -it 5a8bbc397df7 bash
That’s it. You successfully learned how to install Docker on Ubuntu 24.04 and learned how to create and use the Docker container simple commands. Of course, you do not have to do this on your own. You only need to sign up for one of our NVMe VPS Ubuntu hosting plans and submit a support ticket. Our admins will help you with any aspect of the Docker installation and configuration on your server.
If you liked this post on how to install Docker on Ubuntu 24.04, please share it with your friends or leave a comment down below.