Docker: Multistage builds result in multiple images

假如想象 提交于 2021-02-05 11:58:51

问题


Given this small example of a multistage build

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"]

why does this result in 3 images on my local file system?

"<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"

I expected two images, the base image and the server-build image. I used the standard docker build command, i.e.

docker build -t test . 

so which of the parts of the image is none and which is test?

I am confused


回答1:


Each block in the Dockerfile starting with a FROM line creates a new image. If you use a docker build -t option, only the last stage gets tagged with the name you specify; the remaining blocks will appear as <none> in places like docker images output.

# 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
...

You will occasionally see Dockerfiles where a base image is reused in later build stages, and there it will not show up at all in docker images output.

# 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


来源:https://stackoverflow.com/questions/61234588/docker-multistage-builds-result-in-multiple-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!