Skip to content
Advertisement

How to give name or tag for intermediate image?

I used docker to build my Java application and I using the multi-stage building and I have some problems every time when I run the docker command for building the docker creates new intermediate image with tag and name none and I need the possibility to called intermediate containers.

That is my dockerfile:

JavaScript

and after each running docker build command I had a many none images:

JavaScript

How can I replace none name of intermediate images to my_image_name?

Advertisement

Answer

you can use docker build -t image_name to tag the image.But intermediate images will have <none> as the image name.

<none> images are formed as part of the multistage builds. If there are multiple FROM in your dockerfile then building image will create multiple images along with <none> images which are intermediate images used by main image.

for example

dockerfile:

JavaScript

In the above dockerfile I am using ubuntu:18.04 as intermediate image which is used again in the COPY command above. HERE COPY --from=compile-image /root/helloworld .

So When I build an image using above dockerfile by command

JavaScript

The above command will create two images as below.

JavaScript

<none> is an intermediate image. which is again internally used in the dockerfile.

now the solution for your question would be creating two docker files and using them separately.

For example, the above dockerfile can be divided into two dockerfiles and can be used to create separate images without any intermediate image.

dockerfile 1:

JavaScript

and execute $ sudo docker build -t compile_image .

by changing docker file again

docker file 2:

JavaScript

and execute: $ sudo docker build -t runtime_image .

the output will not have intermediate images. Hence no <none> images.

JavaScript

FYI: In second docker file, I used previously build image compile_image in COPY command

COPY --from=compile_image /root/helloworld .

Here compile_image acts like an intermediate image.

If you observe previous images the memory occupied by <none> and compile_image are same and sample_image and runtime_image are the same. The main purpose of using the multistage builds is to reduce the size of an image.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement