Best practice to upgrade Jenkins docker containers.
Important Pointers:
- always prefer docker volumes. This method works if you are running Jenkins docker container with mounted volume.
Traditional way is to get into the container and download the new war file, replace & finally restart the container.
There are chances container may not start and due any incorrect changes. :(
let’s look at the more effective way to meet this.
- Log in to your host server.
- Directly pull a Jenkins docker image with your desired version. docker pull jenkins/jenkins:2.54
(assuming 2.154 is the latest) If you are planning to install any additional packages, it is better to have dockerfile and build your own image.
Stop your current docker container.
docker stop CONTAINER_ID
Start your new container with the existing location of jenkinshome.
docker container run \ — name jenkins \ -p 8080:8080 -p 50000:50000 \ -v $HOME/jenkins:/var/jenkins_home \ -d \ jenkins/jenkins:2.514
$HOME is the your local directory for docker volume.
- Check for the running container. Now and access your Jenkins web with latest version
Note: Having a separate volume for Jenkins home makes easier to upgrade the Jenkins version in clicks. And all our settings, personalisation in place.
peace!