【Docker】Dockerfile 最佳实践-ONBUILD
参考教程:https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
环境
- virtual box 6.1
- centos 7.8
- docker 19.03
ONBUILD
An ONBUILD
command executes after the current Dockerfile
build completes. ONBUILD
executes in any child image derived FROM
the current image. Think of the ONBUILD
command as an instruction the parent Dockerfile
gives to the child Dockerfile
.
当前的 Dockerfile 构建完成后,将执行 ONBUILD
命令。ONBUILD
在派生自 FROM
的任何子镜像中执行。可以将 ONBUILD
命令视为父 Dockerfile 给子 Dockerfile 的指令。
A Docker build executes ONBUILD
commands before any command in a child Dockerfile
.
Docker 构建在子 Dockerfile
中的任何命令之前执行 ONBUILD
命令。
ONBUILD
is useful for images that are going to be built FROM
a given image. For example, you would use ONBUILD
for a language stack image that builds arbitrary user software written in that language within the Dockerfile
, as you can see in Ruby’s ONBUILD
variants.
ONBUILD
对于将要构建的镜像 FROM
给定镜像很有用。例如,您可以将 ONBUILD
用于语言堆栈映像,以构建在 Dockerfile 中以该语言编写的任意用户软件,如 Ruby’s ONBUILD
variants。
Images built with ONBUILD
should get a separate tag, for example: ruby:1.9-onbuild
or ruby:2.0-onbuild
.
用 ONBUILD
构建的图像应获得一个单独的标签,例如:ruby:1.9-onbuild
或 ruby:2.0-onbuild
。
Be careful when putting ADD
or COPY
in ONBUILD
. The “onbuild” image fails catastrophically if the new build’s context is missing the resource being added. Adding a separate tag, as recommended above, helps mitigate this by allowing the Dockerfile
author to make a choice.
将 ADD
或 COPY
放入 ONBUILD
时要小心。如果新构建的上下文缺少要添加的资源,则 “onbuild” 映像将灾难性地失败。如上所述,添加一个单独的标签可以通过允许 Dockerfile 作者做出选择来缓解这种情况。
总结
介绍了 Dockerfile 的 ONBUILD 指令的最佳实践。
相关文章
- Docker容器的使用
- docker中,将容器中的文件拷贝到宿主机上
- 转转测试环境docker化实践
- CentOS下Docker安装
- docker swarm实践爆心肝总结全在这里,火速收藏!!!
- 创建Docker镜像
- Linux有问必答:如何在Ubuntu中升级Docker
- 如何在 Fedora 22 上面配置 Apache 的 Docker 容器
- docker 几种磁盘卷挂载方式的区别
- docker中简单安装redis
- Docker nginx+php+memcache安装遇到的几个小问题
- docker入门与实践
- Suse12离线安装docker
- docker-compose部署ELK(亲测)
- Windows下启动Docker容器遇到Error invoking remote method ‘docker-start-container‘: Error解决办法
- 【MAC】手动下载安装docker
- 《Docker生产环境实践指南》——第2章 技术栈 2.1构建系统
- Docker环境搭建与使用:docker常用的命令
- 狂神说Docker进阶笔记
- Docker安装PostgreSQL
- 《Docker技术入门与实战》——1.2 为什么要使用Docker
- 《Docker技术入门与实战》——3.1 获取镜像
- Docker快速指南
- Docker配置阿里云镜像加速
- 品高公开课 | 基于Docker容器的微服务架构实践