Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to have Jenkins "update" a running docker container when the image has been updated

Our organization is relatively new to Docker and Jenkins. We are working on developing our CI pipeline from (Java) Source Code update to Running Application.

Currently Jenkins is using the Cloudbees Docker Build and Publish plugin to Update the Image after a successful build. It simply pulls the base (JBoss) image and updates it with the App's WAR file it just built (via Maven).

We are using the "Send commands over SSH" build step to SSH into the server the (currently running) container is on, stop the container with the specified image ID, and re-pull and subsequently run the container.

However, I know there has to be a better, more elegant way to do this. Surprisingly enough, I'm having trouble finding documentation on just how to do it. Any advice would be appreciated. Please let me know.

like image 381
daniel9x Avatar asked Feb 15 '16 15:02

daniel9x


2 Answers

If you want to only use Docker, there is not much more you can do. Using Jenkins with Docker is already a good step forward. Perhaps you could docker stop instead of ssh shutdown but this won't make things much better.

There are tools out there like Openshift and Fabric8 that help you build a CI and CD workflows. This should help. Note, however, if you look closer to them you will see that several of them are built on top of Kubernetes.

If you are looking for a workflow ready to use, give Openshift a try. Have a look at it's architecture overview. It has a Jenkins plugin that make your life easier.

If you want to make a step forward at the same time you build your own workflow, no doubt Kubernetes is the way to go. It just put tons of facility in order to build your cluster of containers without imposing you some workflow. Have a look at this overview and the getting started from CoreOS docs.

like image 127
Joao Morais Avatar answered Oct 22 '22 08:10

Joao Morais


There's a so-called watchtower docker image. Github: https://github.com/containrrr/watchtower, docker hub: https://hub.docker.com/r/containrrr/watchtower.

You use it as a side-car to the containers you want to update. Watchtower runs alongside your app, watches for pushes to the specified tags and updates your app if there is a push.

You give up control over downtime though. Containers usually don't start instantly.

like image 32
clorz Avatar answered Oct 22 '22 09:10

clorz