How to set image name in Dockerfile?

Better Stack Team
Updated on October 5, 2023

You can set the image name in a Dockerfile using the FROM instruction. The FROM instruction specifies the base image that your Docker image will be built upon.

The basic syntax of the FROM instruction is:

 
FROM image:tag
  • image: The name of the base image you want to use.
  • tag: The tag of the base image you want to use.

For example, to set the image name to my-image in your Dockerfile, you can use the following FROM instruction:

 
FROM my-registry/my-image:latest

In this example, my-registry is the hostname of the private registry, my-image is the name of the image, and latest is the tag of the image.

When you build the Docker image using this Dockerfile, the resulting Docker image will have the name my-registry/my-image:latest. You can then push this image to your Docker registry or use it locally on your machine.