Press enter or click to view image in full size
While there are probably a thousand ways to version your Docker images, I am going to show you a very simple way, using methods that have become quite common. It will ensure your image’s versions match your Git version tags, so you know exactly which code is inside the image.
UPDATE: A more recent article I wrote about versioning is available here.
This tutorial assumes you already have a Dockerfile that builds your image.
Version File
First, create a VERSION file with nothing in it but the version numbers:
0.0.1You want to store this VERSION file in the image for completeness (and because your program can use it to display the version), so add the following to your Dockerfile:
ADD VERSION .That will add the VERSION file to your WORKDIR.
Build script
If you don’t already have a build script, create one and call it build.sh. The simplest form of this is just to run your docker build:
set -ex# SET THE FOLLOWING VARIABLES
# docker hub username…