Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tag an image in a Dockerfile? [duplicate]

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?

like image 343
Jérôme Verstrynge Avatar asked Aug 17 '16 09:08

Jérôme Verstrynge


People also ask

How do I tag an image in a Dockerfile?

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.

Does docker tag copy the image?

You can just docker tag it with the new label. You can't duplicate it, but you also can't change the image in any way (beyond relabelling it) so it shouldn't make a difference. Docker tagging works as an effective copy You reference a new image (as listed via docker images ) with tag :1.4.

Which command is used to tag an image in docker?

Explicitly tagging an image through the tag command. This command just creates an alias (a reference) by the name of the TARGET_IMAGE that refers to the SOURCE_IMAGE. That's all it does. It's like assigning an existing image another name to refer to it.


1 Answers

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.

like image 73
Bukharov Sergey Avatar answered Sep 18 '22 15:09

Bukharov Sergey