Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker build command with --tag unable to tag images

Tags:

I have trying to build a Docker image using a Dockerfile available locally.

docker build -t newimage . 

I have used this command multiple times earlier too, but somehow its not working currently and i am stuck finding the reason for it.

I will be really helpful if someone can help me with a possible solution or a possible area to look for an issue.

i already had a look over other posts that could have been related for example : Docker build tag repository name

like image 316
Harshil Avatar asked Aug 05 '16 11:08

Harshil


People also ask

Which command is used to build and tag the docker image?

With Dockerfile written, you can build the image using the following command: $ docker build .

Which technique is used to tag a docker image?

To apply a Docker image tag to a build, use the -t switch.

Does a docker image need a tag?

To push an image to a private registry and not the central Docker registry you must tag it with the registry hostname and port (if needed).


2 Answers

Okay! I found out the reason for issue.

DOCKER BUILD PROCESS

When we build a docker image, while creating a image several other intermediate images are generated in the process. We never see them in docker images because with the generation of next intermediate image the earlier image is removed.And in the end we have only one which is the final image.

The tag we provide using -t or --tag is for the final build, and obviously no intermediate container is tagged with the same.

ISSUE EXPLANATION

When we try to build a docker image with Dockerfile sometimes the process is not successfully completed with a similar message like Successfully built image with IMAGEID

So it is so obvious that the build which has failed will not be listed in docker images

Now, the image with tag <none> is some other image (intermediate). This creates a confusion that the image exists but without a tag, but the image is actually not what the final build should be, hence not tagged.

like image 117
Harshil Avatar answered Sep 28 '22 11:09

Harshil


If your Dockerfile's last line is RUN then it may hang on that during build.

I changed RUN npm start to CMD ["npm", "start"] and it's tagging now.

like image 42
Daniel Kaplan Avatar answered Sep 28 '22 11:09

Daniel Kaplan