问题描述
我正在尝试使用本地可用的 Dockerfile 构建 Docker 映像.
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.
我已经查看了其他可能相关的帖子,例如:Docker 构建标签存储库名称
i already had a look over other posts that could have been related for example :Docker build tag repository name
推荐答案
好的!我找到了问题的原因.
Okay! I found out the reason for issue.
DOCKER 构建过程
当我们构建一个 docker 镜像时,在创建镜像的过程中会生成其他几个中间镜像.我们从未在 docker images
中看到它们,因为随着下一个中间图像的生成,较早的图像被删除.最后我们只有一个是最终图像.
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.
我们使用 -t
或 --tag
提供的标签是用于最终构建的,显然没有中间容器使用相同的标签.
The tag we provide using -t
or --tag
is for the final build, and obviously no intermediate container is tagged with the same.
问题说明
当我们尝试使用 Dockerfile 构建 docker 镜像时,有时该过程未成功完成,并显示类似 Successfully built image with IMAGEID
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
所以很明显,失败的构建不会在docker images
So it is so obvious that the build which has failed will not be listed in docker images
现在,带有标签 <none>
的图像是其他图像(中间).这会造成图像存在但没有标记的混淆,但图像实际上不是最终构建应该是的,因此没有标记.
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.
这篇关于带有 --tag 的 Docker 构建命令无法标记图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!