Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in DevOps and Agile by (2.3k points)

Now normally I know that we can change the name of a docker image like this :

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

How can we do this ( define the name) inside of a Dockerfile. This way I wouldn't have to keep on writing the docker build command.

1 Answer

0 votes
by (6.9k points)

Normally this isn't supported by dockerfile and hence the docker build command is used.

Well there is a workaround - you can try using docker-compose.yml file as it easily identifies the target image name, so if you run the docker-compose build command it will work.

Make sure your docker-compose file looks something like this :

version: '2'

services:
  man:
    build: .
    image: guy/dude:v2

But this isn't standard, you should rather try running a small shell script that will pass all the arguments and also will include the docker image name.

Incase of production the build can be handled by jenkins or whichever CI/CD server you are using, it will have the name of the image inside the pipeline code.

Hope that helped :)


Docker can be a little tough to understand without the help of people who have actual industry experience, so if you are interested try docker training course.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...