Skip to content

Instantly share code, notes, and snippets.

@sax1johno
Created August 16, 2016 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sax1johno/37608b864a871a2a2d621afbd0b99122 to your computer and use it in GitHub Desktop.
Save sax1johno/37608b864a871a2a2d621afbd0b99122 to your computer and use it in GitHub Desktop.
I just worked out another flow to have Zero downtime (mainly for web apps).
Proxy
We use jwilder/nginx-proxy to handle routing to app servers, this will assist us in dynamically routing requests to services.
First Deploy
For the first deploy run docker-compose --project-name=app-0001 up -d.
Rolling Update
We edit the docker-compose.yml with the new image id and run docker-compose --project-name=app-0002 up -d. We now have version 0.2 of the app up and running. The load balancer will already begin routing requests, and given we are using nginx LB we will have 0 downtime.
If you need to reach a desired scale you can now run that command to scale up resources before you shutdown the older version.
Now we can do docker-compose --project-name=app-0001 stop to close down the previous deploy. (Optionally we can run an rm to remove the data - but it might be a good idea to only remove this on the next deploy i.e. deploy app-0003 up, app-0002 stop, app-0001 rm).
Truly rolling update
If you have reasoning behind limiting the number of resources running at a given time you could simply stagger the scale. I.e:
app-0001 scale web=10
...
app-0001 scale web=8 app-0002 scale web=2
app-0001 scale web=6 app-0002 scale web=4
app-0001 scale web=8 app-0002 scale web=2
app-0001 scale web=10 app-0002 scale web=0
...
app-001 stop
Rollback
A rollback is also quite simple, run up on 0001 and stop on 0002.
80/20 deploy
This would be as simple as running scale web=2 on app-0001, and scale web=8 on app-0002.
Automate Everything
This also reminds me of a similar deploy strategy to capistrano, I might even look at using a similar tool to wrap docker-compose and save a rewrite of the deploy logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment