简体   繁体   中英

How to release docker image with Jenkins pipeline

I have a project to build a docker image, in my case it's a extension of mongo image which contains (inside the container) data. And I use this mongo docker image for integration tests purpose.

At the moment, Maven is not used to build the project. When I want to release a version of this image, I do it on my computer which is not ideal.

I would like to kept a file which contains my current version of my docker image (like pom.xml).

What should I do, add a pom.xml in my project for versionning and maven-release-plugin, add a simple version.txt which I update with during my release process ?

Or is there a like "docker.version" file I do not know to do this ?

I post an example of my project on GitHub : https://github.com/Ameausoone/mongodb-docker-with-data

First thing is to have a specific repo for each project that you have . This helps not to mess up the docker images while pushing it to the repository.

You can use the shell scripts/commands in the pipeline script to execute all the commands which are mentioned here.

There are multiple ways in which you push the docker images to the repository.

Tagging based on Time and Build Number:

Take an example of auth-api, where we create an env variable called $DOCKER_TAG in the jenkins and set it to the time the build is created:

DOCKER_TAG: $(date +%Y%m%d).$BUILD_NUMBER 

$BUILD_NUMBER is provided as part of Jenkins job. Now tag the docker image as follows:

docker tag DOCKER_IMAGE auth-api/<DOCKER_IMAGE>:<DOCKER_TAG>

(Assuming you have built the docker image and push it to the repository after tagging- above step.)

NOTE : Docker allows to push the image only if it matches the REPO-NAME)

It helps to find out the docker image creation date and time along with the build number. This image can be deployed to different environments like dev, test, prod.

Tagging based on the environment

Tag the docker image based on the deployment environment, ie dev, test, prod. Configure an environment variable in the pipeline script, using withenv , which may look something like this:

docker tag DOCKER_IMAGE auth-api/<DOCKER_IMAGE>:$ENV

This will help to have a deployment specific docker images.

You can even tag the docker image based on git commit.[not tested personally]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM