44

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?

3
  • 1
    Can't the cmd docker build -t shykes/myapp:1.0.2 -t shykes/myapp:latest . resolve you issue?
    – Tuan
    Commented Aug 17, 2016 at 10:23
  • 3
    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. Commented Oct 19, 2021 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
    Commented Aug 26, 2022 at 23:36

1 Answer 1

46

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.

1
  • 1
    The Zsh script can be quite compact: docker build -t project:${1:-'latest'} .
    – David J.
    Commented Jan 3 at 15:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.