首页 > 解决方案 > Docker 镜像构建以悬空镜像结束

问题描述

我的 Dockerfile:

FROM ubuntu:latest

ENV STAR_VERSION=2.7.3a
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
        && apt-get install -y git-all \
        && apt-get install -y --no-install-recommends apt-utils \
        && apt-get install -y --no-install-recommends build-essential \
        && apt-get install -y make \
        && apt-get install -y libz.dev \
        && echo "downloading ${STAR_VERSION}"

WORKDIR /mnt/d/github/Docker/STAR_2.7.3a/

RUN git clone https://github.com/alexdobin/STAR.git \
        && cd STAR/source \
        && echo "making STAR ${STAR_VERSION}" \
        && make STAR

CMD ["STAR", "--version"]

构建图像:

docker image build .

它表明它已成功构建(尽管有一些警告)但是当我检查它时

$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              e57297dc089d        29 minutes ago      1.41GB
<none>              <none>              8c4d6c6be0d2        About an hour ago   915MB
<none>              <none>              a2625623ebb7        2 hours ago         754MB
$ docker image ls --filter dangling=true
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              e57297dc089d        30 minutes ago      1.41GB
<none>              <none>              8c4d6c6be0d2        About an hour ago   915MB
<none>              <none>              a2625623ebb7        2 hours ago         754MB

为什么他们都在摇晃而没有标签?

标签: docker

解决方案


默认情况下,您从Dockerfile构建的映像是未标记和未命名的。

您需要将repo:tagas 选项传递给构建命令才能标记它们。

docker image build --tag some/repo:tag . 

从文档中:

--tag , -t      Name and optionally a tag in the ‘name:tag’ format

来源:https ://docs.docker.com/engine/reference/commandline/image_build/

请注意:如果您使用相同的标签重新标记另一张图像,也可能会发生未标记的图像,也就是说,从现有图像中窃取标签,使旧图像未标记。

这将显示未标记的图像,它们是图像树的叶子(不是中间层)。当新构建的图像repo:tag从图像 ID 中移除,将其保留为原样 <none>:<none>或未标记时,就会出现这些图像。如果在容器当前正在使用图像时尝试删除图像,则会发出警告。通过具有此标志,它允许进行批量清理。

来源:https ://docs.docker.com/engine/reference/commandline/images/#filtering


推荐阅读