Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build an image with a custom name?

Tags:

docker

When I build an image using docker build:

docker build .

I get an image with a random name.

How to create a docker image with a custom name?

I already know how to set the name in the Dockerfile, but I'm not sure how to use it in the build command.

like image 610
Maroun Avatar asked Jan 09 '18 16:01

Maroun


People also ask

How do I create a docker image from Dockerfile with name?

To build a docker image from a file named other than Dockerfile, specify the Dockerfile name using the -f option. The above command will build the docker image by reading instructions from Dockerfile. dev file in /home/$USER directory.

How do you put a name on a docker image?

You can rename your docker image by docker tag command. Use the below given command to do that. To rename docker container, use the rename sub-command as shown, in the following example, we renaming the container discourse_app to a new name disc_app.


1 Answers

You can use the -t flag, as shown in the documentation (or run docker build --help to learn about the options you have).

You should do:

docker build -t my-image .

Now the image is created with the name my-image:

$ docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
my-image                    latest              43070bef9dfa        2 minutes ago       464MB
like image 142
Maroun Avatar answered Oct 23 '22 13:10

Maroun