The script will create a Docker image from a Dockerfile from the same folder. The image will be taged with latest and additional with the short git hash of the last commit. The image will be pushed to the default docker registry. Replace my-company and my-image-name with the real names.

{:codelabel="shell" filename="createDockerBuilder.sh"}
#!/bin/sh

IMAGE_NAME=my-company/my-image-name

LAST_COMMIT=$(git rev-parse --short HEAD)
echo $LAST_COMMIT
docker build . --file Dockerfile --tag $IMAGE_NAME --build-arg LAST_COMMIT=$LAST_COMMIT
docker tag $IMAGE_NAME $IMAGE_NAME:$LAST_COMMIT

docker push $IMAGE_NAME:$LAST_COMMIT

Build a docker image with build-args to overwrite the ARG inside the Dockerfile.

docker build . --file Dockerfile --tag kargware/notes-builder --build-arg LAST_COMMIT=$(git rev-parse --short HEAD)