educative.io

Creating an image on docker

why did we use the name as ‘hello’ in the command “docker build -t hello .” when we saved the file as ‘dockerfile’?

Hello @Sai_Aligeri,

You are right. The file is saved as Dockerfile, but the -t hello is used as a name tag to name the docker-image as hello that we just created from the Dockerfile. It does not operate as an address/path to the Dockerfile. To give the path, we used . by default, the docker engine will search for the file name as “Dockerfile” in the same directory.

got it. so if we have a dockerfile saved on a different path we use ‘-f’ switch by specifying the filepath. I understood that we saved the dockerfile as ‘dockerfile’ as part of convention. But are we allowed to save the file with a different name? and if so, should we mention the new name in the filepath for docker to create a new image from the file named differently?

@Sai_Aligeri
Yes, we can save a Dockerfile with a different name. It can be test.Dockerfile as well.
To build this test.Dockerfile we use the following command.
docker build -f dockerFiles/test.Dockerfile -t testOne .

dockerFile/test.Dockerfile is the path to Dockerfile from the current directory.

-t as we discussed earlier is a naming tag. testOne will the name of the image that we just created from the Dockerfile.

1 Like