diff --git a/build.sh b/build.sh
index 754032f20e2a2e00dbb6c3158bac1538a8980447..51e5cacdd9991b721c95e6bb12b16b43c90a14da 100755
--- a/build.sh
+++ b/build.sh
@@ -3,11 +3,17 @@
 #
 # Run with two arguments:
 # arg1: REGISTRY or dockerhub id to use. If given, teh built container is pushed there with tag -dev.
-# arg2: goemaxima version number, used to tag the containers that are built.
+# arg2: goemaxima version number, used to tag the containers that are built. If there is a dash, then
+#       with a tag like 2022071300-1.1.5, only the container for stackmaxima version 2022071300 would
+#       be built and tagged with 2022071300-1.1.5 and 2022071300-latest
 
 REGISTRY=$1
-grep -v '^#' versions | cut -f1 | \
-while read -r ver; do
-	goemaxima_version="$2"
+# note that cut by default outputs the whole line if there is no delimiter
+goemaxima_version="$(echo "$2" | cut -f2 -d-)"
+stack_versions="$(echo "$2" | cut -f1 -d- -s)"
+if [ -z "$stack_versions" ]; then
+	stack_versions="$(grep -v '^#' versions | cut -f1)"
+fi
+for ver in $stack_versions; do
 	/bin/sh buildimage.sh "$ver" "${REGISTRY}" "$goemaxima_version" || exit 1
 done