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
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
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
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
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
Step 7: Update Package List Again
After adding Docker’s repository, update your package list again:
sudo apt-get 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)
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
Step 14: Test Docker
Finally, to ensure that Docker is working properly after the update, run a test container:
docker run hello-world
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.
- 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.
Similar Reads
How to Upgrade NPM Dependencies?
Upgrading NPM dependencies is important to ensure your NodeJS project is updated with the latest features, bug fixes, and security patches This process guarantees compatibility with modern JavaScript environments and increases performance and stability for your projects.NPM (Node Package Manager) is
3 min read
Docker - Hello World
Have you ever experience that in just one second your entire operating system is ready to use? Yes, you heard it right Docker gives you the facilities to use a new operating system in one second. Docker is a program that uses your base OS resources and only consumes 20MB - 50MB RAM to launch a new O
3 min read
How to Backup Docker Volumes
Docker volumes are fundamental entities in managing persistent data that is generated and consumed by Docker containers. Given the stateless nature of the containers, anything that is not maintained inside a volume will be lost when the container stops or is removed. Hence, it's paramount to have a
7 min read
How to Remove Docker Volumes
Docker volumes are a crucial component in Docker that are used to manage persistent data for containerized applications. They are storage units that can be attached to one or more containers, allowing data to be shared and persist beyond the lifecycle of a single container. They are managed by Docke
3 min read
How To Update Existing Docker Image ?
Docker, a powerful containerization platform, allows developers to package applications and their dependencies into lightweight, portable containers. When it comes to managing Docker images, rebuilding them efficiently, and updating the containers are crucial for maintaining consistency and ensuring
8 min read
How to Upgrade a Kubernetes Cluster?
Kubernetes, the open-source field orchestration platform, is continuously evolving to satisfy the demands of modern applications. Regularly upgrading your Kubernetes cluster is essential to leverage new capabilities, safety patches, and overall performance enhancements. In this article, we can dive
10 min read
How to Use a .dockerignore File?
If you are a Docker Developer, you might have noticed that when you build a Docker Image either using a dockerfile or directly pull an image from the Docker registry, the size of the image can be considerably large depending upon your Docker Build Context. Since Docker is a client-server application
4 min read
Use of Docker Playground
Pre-requisite: Docker Play with Docker or Docker Playground is a simple, interactive, and fun playground to learn Docker. It is an open-source platform for building, shipping, and running applications on containers online for learning or testing purposes online. This service is offered by Docker Inc
2 min read
How To Add User To Docker Group?
Adding the user to the docker group is a common practice adding the user to the docker group allows you to interact with the docker daemon without requiring sudo pervillages. Without adding a user to the Docker group, running Docker commands typically requires superuser privileges. Adding a user to
3 min read
Docker Tutorial
Docker is a tool that simplifies the process of developing, packaging, and deploying applications. By using containers, Docker allows you to create lightweight, self-contained environments that run consistently on any system, minimising the time between writing code and deploying it into production.
7 min read