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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github