Skip to main content

How to set the name and tag of the image being built?

The name and tag of a Docker image are set with the -t (or --tag) flag in the docker build command.


Syntax

bash
docker build -t NAME:TAG .

Example

bash
docker build -t myapp:1.0 .

Where:

PartMeaning
myappimage name
1.0tag (version)
.build context (current directory)

Details

  • If no tag is given, Docker assigns latest:

    bash
    docker build -t myapp .

→ this becomes myapp:latest

  • A tag can contain words, digits, environment names:

    javascript
    myapp:dev myapp:prod myapp:v2

Summary

The name and tag are set with the -t flag in docker build, in the name:tag format.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.