How to tag an image in a Dockerfile?

Jérôme Verstrynge picture Jérôme Verstrynge · Aug 17, 2016 · Viewed 29k times · Source

I have been digging the documentation, but I did not find an instruction to define the tag name of an image in a Dockerfile. There is one available for the command line though.

Say I create an image FROM another image, I don't want it to bear the same name. How should I proceed?

Answer

Bukharov Sergey picture Bukharov Sergey · Aug 17, 2016

Unfortunately it is not possible. You can use build.sh script, which contains like this:

#!/usr/bin/env bash
if [ $# -eq 0 ]
  then
    tag='latest'
  else
    tag=$1
fi

docker build -t project:$tag .

Run ./build.sh for creating image project:latest or run ./build.sh your_tag to specify image tag.