How to Upgrade Docker on Ubuntu?

Docker is an open-source platform that provides assistance to create, deploy, and run various applications in containers. A container is a standalone, lightweight, executable package holding all the required things for an application to run, including libraries, code, and system tools. 

Having the updated version of Docker is the key to using the Docker services smoothly.

Considering its importance, this guide will instruct how to upgrade Docker on Ubuntu which ensures the security, stability, and performance of the system.

How do I Upgrade Docker on Ubuntu?

Docker provides a manner for developers to build and deploy applications in a stable way. To upgrade Docker on Ubuntu, follow the below steps:

Step 1: Check the Current Version

Before upgrading Docker, it is a good practice to check the current version that is installed on the system. It is possible by running the “docker” command with the “version” option in a terminal:

$ docker --version

It displays the version number “19.03.0” of the Docker engine that is currently installed on the existing system.

Step 2: Uninstall the Current Version 

To upgrade Docker, first uninstall the current version that is installed on the operating system. For this, execute the following command by using the “apt” package manager with the “remove” option:

$ sudo apt remove docker docker-engine docker.io

It removes the existing Docker packages from the current system.

Step 3: Verify the Uninstallation 

Once the Docker has been removed, verify the removal by running the following command:

$ docker --version

Now, it’s time to get the latest Docker. 

Step 4: Install Dependencies 

Once the old version of Docker has been removed, install the dependent packages by running the following commands:

$ sudo apt install apt-transport-https ca-certificates curl software-properties-common

The output shows that all dependent packages have been installed.

Step 5: Add Docker GPG Key

To add the docker GPG key, utilize the “curl” command with the “fsSL” options to extract data from a server: 

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

The output shows that a docker GPG key has been added to the system.

Step 6: Add Repository

To add the Docker package repository to the system’s package sources, utilize the “add-apt-repository” command by specifying the repository URL for the Docker package. The “[arch=amd64]” specifies the package architecture to download (in this case, the 64-bit version):

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Step 7: Update the Package Index

To update the local package index with the latest information about available packages from the configured software repositories, execute the below script:

$ sudo apt update

It checks the configured software repositories for updates and downloads the latest package lists. 

Step 8: Install the Docker CE Package (Upgrade)

To install the Docker CE (Community Edition) package from the official Docker repository, specify the “docker-ce” package name:

$ sudo apt install docker-ce

It downloads the latest Docker CE package from the official Docker repository and installs it in the system. It includes the Docker runtime, which allows users to create, run, and manage Docker containers on your system.

Step 9: Verify the Installation 

Once the new version of Docker has been installed, verify the installation by running the following command:

$ docker --version

It displays the version number “23.0.1” of the new Docker engine that is now installed on the system.

Conclusion

To upgrade Docker to the latest version in Ubuntu, first, uninstall docker’s old version with all dependencies. After that, download the latest Docker CE package from the official Docker repository and install it in the system. It provides the latest features and functionality, while also decreasing the chance of security vulnerabilities and other issues.

This article has explained how to upgrade docker in Ubuntu.