Open In App

How to Upgrade Docker ?

Last Updated : 18 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Docker is a widely used platform for containerizing applications, and keeping Docker up-to-date ensures you're benefiting from the latest features, security patches, and performance improvements. This article will guide you through the step-by-step process of updating Docker on a Linux system, specifically for distributions like Ubuntu and CentOS.

Why You Should Update Docker

Updating Docker regularly is important for several reasons:

  • Security: Docker updates frequently include patches for known vulnerabilities.
  • New Features: Get access to the latest Docker features that help improve performance and functionality.
  • Bug Fixes: Updating ensures that you’re running the most stable version of Docker, with fewer bugs and issues.
  • Performance Improvements: Each release often comes with optimizations that can enhance container performance.

What is Docker Upgrade?

  • As for Docker Upgrade, it is applicable for Docker Version below 24.0.6.
  • For updating Docker on Ubuntu StudioWorkspaceInstance or AppDeploymentInstance where the SSH user does not have the root or sudo, and for updating Docker on the RHEL OS instance where the SSH user may or may not have root/sudo level privileges, follow the below steps. Also, to improve security, adequately manage the user and application containers, this involves putting them in hibernation mode or passivating them using the launchpad.
  • For Ubuntu if the SSH user does not have privileges needed to perform an upgrade then someone with privileges would have to be asked to do the upgrade. On RHEL you can continue with/without superuser privileges depending on the right that a user has. Last of all, use the launchpad to oversee the running of the containers, and put them on standby or make them dormant, in preparation for the upgrade process.

How to Upgrade Docker: Step-by-Step Guide

Step 1: Check the Current Version of Docker

Before updating, check the current version of Docker installed on your system:

docker --version
dockerversion1

Step 2: Uninstall the Old Version of Docker (Optional)

While it’s optional, you may choose to uninstall the old version of Docker. You can uninstall Docker without removing images, docker containers, docker volumes, or configuration files.

To Uninstall Docker:

 sudo apt-get remove docker docker.io containerd runc
dockeruninstall

Step 3: Update the Package Repository

Make sure your package repository is up-to-date before updating Docker:

For Ubuntu/Debian:

sudo apt-get update
sudoupdate

For CentOS:

sudo yum update

Step 4: Install Prerequisites

You need to install some prerequisite packages:

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
pre-requsites

Step 5: Add Docker’s Official GPG Key

Add Docker's GPG key for verification:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Step 6: Set Up Docker’s APT Repository

Now, add Docker’s repository to your system:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

add-and-setup

Step 7: Update Package List Again

After adding Docker’s repository, update your package list again:

sudo apt-get update
update

Step 8: Install Docker (or Update)

If Docker is already installed, this command will update it to the latest version. Otherwise, it will install Docker:

sudo apt-get install docker-ce docker-ce-cli containerd.io 
docker-buildx-plugin docker-compose-plugin

For CentOS:

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

If the above command is not working then first execute the following command and then execute the above. (only step 9)

dockerinstall

Step 9: Unmask the Docker Service

Run the following command to unmask the Docker service:

sudo systemctl unmask docker

Step 10: Start the Docker Service

After unmasking, you can start the Docker service with:

sudo systemctl start docker

Step 11: Enable Docker to Start at Boot

To ensure Docker starts automatically on system boot, run:

sudo systemctl enable docker

Step 12: Verify Docker is Running

You can check if Docker is running with:

sudo systemctl status docker

Step 13: Verify Docker Version

To verify that Docker has been updated successfully, check the version again:

docker --version
dockerinstall

Step 14: Test Docker

Finally, to ensure that Docker is working properly after the update, run a test container:

docker run hello-world
dokerhello

Common Issues During Docker Upgrades and How to Fix Them?

Dependency Conflicts

While you are trying to upgrade Docker, it is very common to face conflicts between Docker's dependencies and system libraries.

Solution

Ensure that your system is fully updated before attempting the Docker upgrade. Use `sudo apt update` (for Ubuntu) or `yum update` (for RHEL) to update all system packages.

Permission Denied Errors

Many users face "Permission denied" errors when they do not have access right to install or upgrade Docker.

Solution

Ensure you have root or sudo privileges before proceeding. If lacking these, request an administrator to perform the upgrade.

Old Docker Versions Still in Use

After upgrading, Docker may still be pointing to an old version, causing confusion and errors.

Solution

Use `docker --version` to confirm the upgrade. If the old version persists, restart the Docker service with `sudo systemctl restart docker` or reboot your system.

Service Not Starting After Upgrade

After upgrading, Docker may fail to start due to configuration issues or incomplete installations.

Solution

Check Docker’s service logs (`sudo journalctl -u docker`), and if necessary, run `sudo systemctl daemon-reload` to refresh system services.

How to Safely Upgrade Docker Without Downtime

Hibernating Active Containers

  • On the upgrading process, it is recommended that the running containers should be put to sleep or stopped in a way in order not to affect any processes.
  • Suspend containers by using the docker pause <container_id> statement pauses the operation of the containers without necessarily stopping them.

Performing Blue-Green Deployment for Zero Downtime

  • Critical applications environment are well supported by blue-green deployment strategy since it allows seamless availability.
  • Substitute your containers to a new environment that has not been touched yet (blue) while at the same time keep the previous environment (green) running. When Docker upgrade is done, move traffic to the new (blue) containers.

Backing Up Docker Data

  • To work with specific images use `docker save` and to work with volumes use `docker volume ls` to list them and back them up. This makes that whenever something went wrong during the upgrade then the previous setup will always be available.

Testing the Upgrade in a Staging Environment

  • Due to such possibilities, the Docker upgrade should initially be tried on the system that is not the production one or is a staging server. This enables one to arrest such problems before they impact on live services that are accessible by customers.

Conclusion

Keeping Docker updated is crucial for maintaining a secure, feature-rich, and high-performance container environment. Following this guide, you’ve successfully updated Docker to the latest version, verified the installation, and learned how to troubleshoot common issues. Whether you’re a beginner or experienced in container management, updating Docker regularly will help you make the most out of its features and capabilities.


Next Article
Article Tags :

Similar Reads