How to set image name in Dockerfile?

gvlasov picture gvlasov · Aug 17, 2016 · Viewed 325.3k times · Source

You can set image name when building a custom image, like this:

docker build -t dude/man:v2 . # Will be named dude/man:v2

Is there a way to define the name of the image in Dockerfile, so I don't have to mention it in the docker build command?

Answer

salehinejad picture salehinejad · Mar 13, 2017

How to build an image with custom name without using yml file:

docker build -t image_name .

How to run a container with custom name:

docker run -d --name container_name image_name