Application rollbacks mean going back to an older version of your software. This is useful when a new update causes issues.
Docker containers and version control systems like Git make rollbacks much easier. They let you save different versions of your app code and switch between them swiftly.
So when a new update has bugs, we can quickly rollback to a previous version that worked fine. This saves a lot of time and troubleshooting effort.
Docker makes rollbacks easy in 2 ways:
- Images - A Docker image contains an app and all its dependencies. By versioning images, you save snapshots of the app at different stages.
- Isolation - Docker isolates apps from each other and the host OS. So rolling back an app has no impact on other apps or the system.
This is unlike traditional deployment where apps are tightly coupled with the system. Rolling back means undoing complex configuration changes.
With Docker, you just run an older image. All dependencies and configs are inside the image. So rollbacks are simple - you just switch images.
- Semantic Versioning: Adopting a semantic versioning scheme (e.g., MAJOR.MINOR.PATCH) for your images can help you quickly identify the significance of each version. Change in the MAJOR version indicates incompatible changes, while changes in the MINOR version represent backward-compatible additions.
- Branch-based Tagging: You can choose to tag images based on the Git branch they originate from. This approach is useful for maintaining separate images for different development branches.
Let's walk through a simple example of rolling back a Dockerized web application using versioned images:
- Initial State: Start with the latest version of your Dockerized web app running successfully.
- Create a New Image: Make changes to your application code. Once you're ready to commit, tag the image with a version number or commit hash.
docker build -t myapp:v2 .
- Deployment: Push the new image to your image repository or registry.
docker push myapp:v2
- Rollback: Suppose an issue arises in the new version. To roll back, simply redeploy the previous version's image.
docker run -d -p 80:80 myapp:v1
Thanks for reading this article, I hope you found it interesting!
Let's connect on Github: https://github.com/shricodev
See you next time!😉