Docker:多阶段构建会产生多个图像
Docker: Multistage builds result in multiple images
给出这个多阶段构建的小例子
FROM node:10 AS ui-build
WORKDIR /usr/src/app
FROM node:10 AS server-build
WORKDIR /root/
EXPOSE 3070
ENTRYPOINT ["node"]
CMD ["index.js"]
为什么这会在我的本地文件系统上产生 3 个图像?
"<none>";"<none>";"58d63982fbef";"2020-04-15 17:53:14";"912MB"
"node";"10";"bd83fcefc19d";"2020-04-14 01:32:21";"912MB"
"test";"latest";"3913dd4d03b6";"2020-04-15 17:53:15";"912MB"
我需要两个映像,基本映像和服务器构建映像。我使用了标准的 docker 构建命令,即
docker build -t test .
所以图像的哪些部分是none,哪些是测试?
我很困惑
Dockerfile 中以 FROM
行开头的每个块都会创建一个新映像。如果您使用 docker build -t
选项,则只有最后一个阶段会使用您指定的名称进行标记;剩余的块将在 docker images
输出等地方显示为 <none>
。
# node:10 is a base image
# Not the final image, will appear as <none>:<none>
FROM node:10 AS ui-build
...
# The final image, will appear as test:latest (`docker build -t` option)
FROM node:10 AS server-build
...
您偶尔会看到 Dockerfiles,其中基础映像在后期构建阶段被重用,并且根本不会出现在 docker images
输出中。
# Will be hidden because it has descendant images
FROM node:10 AS base
RUN apt-get update && apt-get upgrade
# Will appear as <none>:<none>
FROM base AS ui
...
# Will get the `docker build -t` tag
FROM base
给出这个多阶段构建的小例子
FROM node:10 AS ui-build
WORKDIR /usr/src/app
FROM node:10 AS server-build
WORKDIR /root/
EXPOSE 3070
ENTRYPOINT ["node"]
CMD ["index.js"]
为什么这会在我的本地文件系统上产生 3 个图像?
"<none>";"<none>";"58d63982fbef";"2020-04-15 17:53:14";"912MB"
"node";"10";"bd83fcefc19d";"2020-04-14 01:32:21";"912MB"
"test";"latest";"3913dd4d03b6";"2020-04-15 17:53:15";"912MB"
我需要两个映像,基本映像和服务器构建映像。我使用了标准的 docker 构建命令,即
docker build -t test .
所以图像的哪些部分是none,哪些是测试?
我很困惑
Dockerfile 中以 FROM
行开头的每个块都会创建一个新映像。如果您使用 docker build -t
选项,则只有最后一个阶段会使用您指定的名称进行标记;剩余的块将在 docker images
输出等地方显示为 <none>
。
# node:10 is a base image
# Not the final image, will appear as <none>:<none>
FROM node:10 AS ui-build
...
# The final image, will appear as test:latest (`docker build -t` option)
FROM node:10 AS server-build
...
您偶尔会看到 Dockerfiles,其中基础映像在后期构建阶段被重用,并且根本不会出现在 docker images
输出中。
# Will be hidden because it has descendant images
FROM node:10 AS base
RUN apt-get update && apt-get upgrade
# Will appear as <none>:<none>
FROM base AS ui
...
# Will get the `docker build -t` tag
FROM base