多个FROMs - 这意味着什么 [英] Multiple FROMs - what it means

查看:138
本文介绍了多个FROMs - 这意味着什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为github上的 Linkurious 项目构建码头服务器映像,这需要两个Neo4j数据库和Node.js运行。



我的第一种方法是为我的图像声明一个包含Neo4j的基本图像。参考文档不以任何有用的方式定义基本图像:


基本图像:
没有父级的图像是一个基本的图像


从中我读到,如果该图像本身没有基本图像,我可能只有一个基本图像。 p>

但是什么是基本图像?这是否意味着如果我在FROM指令中声明neo4j / neo4j,那么当我的图像运行时,neo数据库将自动运行并在端口7474的容器内可用?



阅读Docker参考(请参阅: https://docs.docker.com/reference/builder /#from )我看到:


FROM可以在单个Docker文件中多次出现,以创建多个图像。在每个新的FROM命令之前,只需记下提交后输出的最后一个图像ID。


我要创建多个图像吗?看起来我想要的是包含其他图像的内容的单个图像,例如neo4j和node.js



我没有发现在参考手册中声明依赖关系的指令。在RPM中没有依赖关系,为了运行我的图像,调用上下文必须首先安装它需要的图像?



我很困惑...

解决方案


什么是基础图像?


一组文件,另加 EXPOSE 'd ports, ENTRYPOINT CMD

您可以根据该基础图像添加文件并构建新的图像,从 FROM 指令开始的 Dockerfile FROM 是您的新图像的基本图像。


是否意味着如果我声明 neo4j / neo4j FROM 指令中,当我的图像运行时,neo数据库将自动运行,并在端口7474上的容器中可用。 p>

只有不覆盖 CMD ENTRYPOINT

但是图片本身就足够了:如果你必须添加与<$ c相关的文件,你将使用 FROM neo4j / neo4j $ c> neo4j 为您的特定用途 neo4j


FROM 可以在单个Dockerfile中多次出现


不要:有建议删除该功能反正( issue 13026



Issue 14412 提到:


使用多个 FROM 不是真的一个功能,但是一个bug(哦,极限是紧的,而Dockerfile中多个 FROM 的用例很少)。







更新2011年5月(18个月后),使用 docker(moby)17.05-ce



多个FROM 可以在单个Docker文件中使用。

请参见 构建器模式与Docker中的多阶段构建 (通过 Alex Ellis )和 PR 31257 by TõnisTiigi



之前:


构建器模式涉及使用两个Docker映像 - 一个执行构建,另一个用于运行第一个构建的结果,而不需要


之后:


一般Synta x涉及在您的Dockerfile内添加 FROM - 最后一个 FROM 语句是最终的基础映像。要从中间图像复制工件和输出,请使用 COPY --from =< base_image_number>


示例:

  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应用程序

FROM alpine:最新
RUN apk --no-cache add ca-certificates
WORKDIR / root /
COPY --from = builder / go / src / github.com/alexellis/href-counter/app。
CMD [./app]

结果将是两个图像,一个用于建筑,一个只是结果应用程序(很多,很小较小)

 创建标记图像ID SIZE 

多最新bcbbf69a9b59 6分钟前10.3MB
golang 1.7.3 ef15416724f6 4个月前672MB


I want to build a docker image for the Linkurious project on github, which requires both the Neo4j database, and Node.js to run.

my first approach was to declare a base image for my image, containing Neo4j. The reference docs do not define "base image" in any helpful manner:

Base image: An image that has no parent is a base image

from which I read that I may only have a base image if that image has no base image itself.

but what is a base image? does it mean that if I declare neo4j/neo4j in a FROM directive, that when my image is run the neo database will automatically run and be available within the container on port 7474?

reading the Docker reference (see: https://docs.docker.com/reference/builder/#from) I see:

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.

do I want to create multiple images? it would seem what I want is to have a single image that contains the contents of other images e.g. neo4j and node.js

I've found no directive to declare dependencies in the reference manual. are there no dependencies like in RPM where in order to run my image the calling context must first install the images it needs?

I'm confused...

解决方案

what is a base image?

A set of file, plus EXPOSE'd ports, ENTRYPOINT and CMD.
You can add files and build a new image based on that base image, with a new Dockerfile starting with a FROM directive: the image mentioned after FROM is "the base image" for your new image.

does it mean that if I declare neo4j/neo4j in a FROM directive, that when my image is run the neo database will automatically run and be available within the container on port 7474?

Only if you don't overwrite CMD and ENTRYPOINT.
But the image in itself is enough: you would use a FROM neo4j/neo4j if you had to add files related to neo4j for your particular usage of neo4j.

FROM can appear multiple times within a single Dockerfile

Don't: there is a proposal to remove that "feature" anyway (issue 13026)

Issue 14412 mentions:

Using multiple FROM is not really a feature but a bug (oh well, the limit is tight and there is few use cases for multiple FROM in a Dockerfile).


Update May 2017 (18 months later), with docker (moby) 17.05-ce.

Multiple FROM can be used in a single Dockerfile.
See "Builder pattern vs. Multi-stage builds in Docker" (by Alex Ellis) and PR 31257 by Tõnis Tiigi.

Before:

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.

After:

The general syntax involves adding FROM additional times within your Dockerfile - whichever is the last FROM statement is the final base image. To copy artifacts and outputs from intermediate images use COPY --from=<base_image_number>.

Example:

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 .

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

The result would be two images, one for building, one with just the resulting app (much, much smaller)

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

multi               latest              bcbbf69a9b59        6 minutes ago       10.3MB  
golang              1.7.3               ef15416724f6        4 months ago        672MB  

这篇关于多个FROMs - 这意味着什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆