Docker build command with --tag unable to tag images

There's nothing wrong with Docker.

An image can have multiple tags:

alpine    3.4      4e38e38c8ce0        6 weeks ago         4.799 MB
alpine    latest   4e38e38c8ce0        6 weeks ago         4.799 MB

In this example the image with id 4e38e38c8ce0 is tagged alpine:latest and alpine:3.4. If you were to execute docker build -t alpine . the latest tag would be removed from the image 4e38e38c8ce0 and assigned to the newly built image (which has a different id).

If you remove the last tag from an image, the image isn't deleted automatically. It shows up as <none>.

Docker also uses a cache. So if you build an image with a Dockerfile, change that file, built the image again and than undo the change and build again you will have two images - the image you built in the first and last step are the same. The second image will be "tagged" <none>.

If you want to keep multiple version of an image use docker build -ttag:versionimage:tag . where versiontag is changed every time you make some changes.

Edit: What I called tag is actually the image name and what I called version is called the tag: https://docs.docker.com/engine/reference/commandline/tag/


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.


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.