Dockerfile 中是否需要“FROM"子句? [英] Is `FROM` clause required in Dockerfile?
问题描述
对于我遇到的所有 Dockerfiles(诚然不多),它们都使用 FROM
子句来基于现有图像,即使它是 FROM从头开始
.
For all the Dockerfiles I've come across thus (which admittedly is not many), all of them have used a FROM
clause to base off an existing image, even if it's FROM scratch
.
这个条款是必需的吗?是否可以有一个没有 FROM
子句的 Dockerfile?这样创建的容器是否可以做任何事情?
Is this clause required? Is it possible to have a Dockerfile with no FROM
clause? Will this container created thus be able to do anything?
编辑
我读了
没有 FROM 指令的 Dockerfile 没有父镜像,并且被调用基础图像.
A Dockerfile with no FROM directive has no parent image, and is called a base image.
https://docs.docker.com/glossary/?term=parent%20图像
但我认为这可能是一个错误.
But I think this may be an error.
推荐答案
根据官方文档要求:
FROM 指令初始化一个新的构建阶段并设置 Base后续说明的图像.因此,一个有效的 Dockerfile 必须从 FROM 指令开始.图像可以是任何有效的图像——它通过从公共中提取图像特别容易开始存储库.
The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions. As such, a valid Dockerfile MUST start with a FROM instruction. The image can be any valid image – it is especially easy to start by pulling an image from the Public Repositories.
https://docs.docker.com/engine/reference/builder/#来自
这篇关于Dockerfile 中是否需要“FROM"子句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!