What is Blue / Green Deployment?
Blue / Green deployment is a technique companies use to release new versions of their application with no downtime. This technique involves two identical environments running on a single or multiple servers. We will call these Blue and Green environments. On a high level, just imagine that there is a magical switch for you to alternate between the two environments instantly. In this article, I will walk you through how to execute Blue / Green deployment with DigitalOcean and Docker.
Using DigitalOcean’s Floating Ip
DigitalOcean provides services to allow you to create and access Droplets which are essentially servers sitting on their data server centers. They are very similar to AWS’s EC2 instances if you are familiar with that. Once you create an account and are logged in, you can navigate to their Floating IP by clicking Networking on top then Floating IPs underneath. Once you have reached this page, you will be able to create Floating IPs and assign them to your Droplet.
By doing this, you can map the Floating IP to your DNS and assign this Floating IP to a different Droplet anytime and your domain should automatically render the corresponding application. This is definitely one of the easiest ways to implement the Blue / Green Deployment for starters.
Using Docker/Docker Swarm
Docker is a technology that allows you to containerize your applications. To learn more about Docker and how to get started with Docker, please read my other article Getting started with Docker On Ubuntu.
It’s just as simple to implement the Blue / Green deployment strategy with Docker. You can start by creating your first instance, let’s call it test
docker service create —name test -p 8080:8080 —replicas 5 example:1.0
Then let’s assume that you have an updated version of the app example, call it example:2.0, then we can update the service by executing this command
docker service update --image example:v2.0 --update-parallelism 2 --update-delay 15s test
This command updates the 5 replicas of test that you initiated with the first command, to the newer version, two out of the five replicas at a time, with a 15 second delay. There are many more flags along with the
docker service update command, you can read about them here.
There are many more other ways that you can implement the Blue / Green deployment technique in your production environment. But the purpose of this article is for you to have an understanding of what it is and why do companies use it. Be sure to explore other strategies such as Nginx, AWS and more as well. Anyhow, being able to switching between environments with no downtime is a very valuable capability, hopefully this article has given you a good outline of what it is and how to integrate it into your own production environments.