43

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?

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • 1
    Can't the cmd ```docker build -t shykes/myapp:1.0.2 -t shykes/myapp:latest .``` resolve you issue? – Tuan Aug 17 '16 at 10:23
  • 1
    It leaves a taste of incompletion: half of the abstraction lies within Dockerfile, and the rest on the command line. ^^ So why not just using the `FROM` on the command line, and the `RUN` too while at it, thus get rid of the Dockerfile. – Fabien Haddadi Oct 19 '21 at 16:25
  • I use a Makefile for this. The 'build' target lets me just run 'make build' and it executes the 'docker build -t ....' stuff. – TheZeke Aug 26 '22 at 23:36

1 Answers1

44

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.

Andrzej Sydor
  • 1,373
  • 4
  • 13
  • 28
Bukharov Sergey
  • 9,767
  • 5
  • 39
  • 54