
我的第一种方法是为我的图像声明一个包含Neo4j的基本图像.参考文档没有以任何有用的方式定义“基本图像”:
Base image:
An image that has no parent is a base image
从中我读到,如果该图像本身没有基本图像,我可能只有一个基本图像.
但什么是基本形象?这是否意味着如果我在FROM指令中声明neo4j / neo4j,那么当运行我的映像时,neo数据库将自动运行并在端口7474上的容器中可用?
阅读Docker参考(参见:https://docs.docker.com/reference/builder/#from)我看到:
FROM can appear multiple times within a single Dockerfile in order to create multiple images. Simply make a note of the last image ID output by the commit before each new FROM command.
我想创建多个图像吗?看起来我想要的是拥有包含其他图像内容的单个图像,例如neo4j和node.js
我没有找到在参考手册中声明依赖项的指令.没有像RPM这样的依赖关系,为了运行我的图像,调用上下文必须首先安装它需要的图像?
我糊涂了…
what is a base image?
一组文件,加上EXPOSE‘d端口,ENTRYPOINT和CMD.
您可以添加文件并基于该基本图像构建新图像,使用以FROM指令开头的新Dockerfile:FROM之后提到的图像是新图像的“基本图像”.
does it mean that if I declare
neo4j/neo4jin aFROMdirective, that when my image is run the neo database will automatically run and be available within the container on port 7474?
仅当您不覆盖CMD和ENTRYPOINT时.
但是图像本身就足够了:如果必须为neo4j的特定用法添加与neo4j相关的文件,你可以使用FROM neo4j / neo4j.
FROMcan appear multiple times within a single Dockerfile
不要:有提议删除该“功能”无论如何(issue 13026)
Issue 14412提到:
Using multiple
FROMis not really a feature but a bug (oh well, the limit is tight and there is few use cases for multipleFROMin a Dockerfile).
2017年5月更新(18个月后),docker (moby) 17.05-ce.
多个FROM可以在单个Dockerfile中使用.
参见“Builder pattern vs. Multi-stage builds in Docker”(Alex Ellis)和PR 31257(Tõnis Tiigi).
之前:
The builder pattern involves using two Docker images – one to perform a build and another to ship the results of the first build without the penalty of the build-chain and tooling in the first image.
后:
The general syntax involves adding
FROMadditional times within your Dockerfile – whichever is the lastFROMstatement is the final base image. To copy artifacts and outputs from intermediate images useCOPY --from=<base_image_number>.
Dockerfile的第一部分:
FROM golang:1.7.3 as builder
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html
COPY app.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
相同(!)Dockerfile的第二部分:
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"]
结果将是两个图像,一个用于构建,一个仅用于生成的应用程序(更多,更小)
REPOSITORY TAG IMAGE ID CREATED SIZE
multi latest bcbbf69a9b59 6 minutes ago 10.3MB
golang 1.7.3 ef15416724f6 4 months ago 672MB
转载注明原文:docker – 多个FROMs – 意味着什么 - 乐贴网