Now Reading: How to Install Docker on Ubuntu

Loading
svg
Open

How to Install Docker on Ubuntu

January 2, 20246 min read

Docker is the new way to manage applications in containers. This way, you can run your application in a resource-isolated container without affecting the host. Think of containers as an advanced version of virtual machines, only that they are more resource-friendly and portable.

Again, each container is isolated from the others and its software is bundled. Thus, you can have different versions of the program that run on different containers to achieve your build goals. With Docker, you can install the free community edition or get the enterprise edition. For this guide, we will focus on Docker Community Edition and detail how you can install it on Ubuntu.

Two Ways to Install Docker on Ubuntu

Ubuntu supports installing Docker, and there are two approaches you can use. First, you can install Docker from the official Docker repository. This option is ideal if you want to get the latest Docker version. Alternatively, you can follow the simpler method and install Docker from the Ubuntu repositories. However, this option will not give you the latest Docker version.

Let us explain both the methods in detail.

Method 1: Installing Docker from the Ubuntu Repository

With this method of installing Docker, only two steps are required, and Docker will be available on your system.

Step 1: Update Your Repository

It is a good habit to always update the system repository before installing any software.

Step 2: Install Docker

Once you update the repository, you can install Docker by installing the “docker.io” package. Use the following command:

, sudo apart to install docker.io -y

The installation will start, and you will get output similar to the following:

Once the process is complete, you can verify that Docker has been installed successfully by checking its version. We can confirm that we have Docker version 24.0.5 installed for this case. Note that this version is not the latest. However, at the time of writing this post, this is the latest available version of the Ubuntu repositories.

Now you can start your Docker like this:

, sudo systemctl start docker

Check its status to make sure it is active and running.

, sudo systemctl status docker

Finally, let's run a simple “Hello World” with Docker to verify that Docker is working correctly.

, sudo docker run hello-world

That’s it. We have just confirmed that Docker is installed and working on Ubuntu. Now you can go ahead and configure it to suit your needs.

Method 2: Installing Docker from its official repository

For anyone who wants to get the latest Docker version, installing it from its repository is the recommended approach. However, there are more steps involved with this option, and more dependency packages must be installed. To keep an eye!

Step 1: Update the Ubuntu Repositories

Start the installation by updating the Ubuntu repository with the “apt” command.

Step 2: Install Dependencies

Various essential packages should be available on Ubuntu to help install Docker. While some are already installed on some Ubuntu versions, running the following command checks for and installs all the required packages:

, sudo apart to install apt-transport-https ca-certificate curl software-properties-general -y

Step 3: Add GPG Key

Using curl, which we installed with the previous command, get the gpg key needed to check the authenticity of the Docker package.

Here is the command to get the docker gpg key:

, curl -FSSL https:,download.docker.com,linux,ubuntu,gpg , sudo add apt-key ,

You should get an output that shows “OK” to confirm that the GPG key has been added successfully.

Step 4: Get the Docker Repository

Remember, we are installing Docker from its official repository. Therefore, we need to add the Docker repository and get the appropriate version for your Ubuntu system. The following command adds the appropriate Docker repository, and we've included the “lsb_release” command to get the correct version for our system.

, sudo add-appropriate-repository “Deb [arch=amd64] $(lsb_release -cs) steady”

Step 5: Set the Docker installation source

You must specify that the Docker installation source for this case is its official repository, not the Ubuntu repository. For that, use “apt-cache” command as shown in the following:

, fair-cash policy docker-ce

The output displays the candidate variable, whose value is the Docker installation source, showing the latest version you will get after installing it.

Step 6: Install Docker

The last step is to install Docker using “apt”.

, sudo apart to install docker-ce -y

Once the installation is complete, check the Docker version.

Notice how the installed version matches the output we got in step 5 after specifying the installation source. Also, you can see that this method installs Docker version 24.0.7 which is the latest version compared to the one we got from the first method.

conclusion

There are two approaches you can take to install Docker on Ubuntu. This post discusses both the approaches and provides detailed steps that you need to follow to comfortably install Docker on Ubuntu. One approach installs the latest Docker version than the other. Check out both the methods and see which one is convenient for your case.

How do you vote?

0 People voted this article. 0 Upvotes - 0 Downvotes.
svg

What do you think?

Show comments / Leave a comment

Leave a reply

You may like
Loading
svg