1.Dockerfile
1.docker build
docker build 这个动作有一个context 上下文的概念
docker build -f /path/to/a/Dockerfile .
这个动作 通过 -f 参数 指出我们的 Dockerfile 位置,同时指定我们当前的工作目录为构建上下文。如果以当前的目录非常大(构建启动过程会变慢,还会浪费多余的mem)
docker build -t shykes/myapp:1.0.2 -t shykes/myapp:latest .
构建时 可以给指定的 镜像打上相应的tag
下面的例子
[root@fdfs-1 ~]# docker build -t weaveworks/scope:1.11.2 -t weaveworks/scope:latest -f /tmp/Dockerfile /tmp/
Sending build context to Docker daemon 119.8kB 传送安全上下文
Step 1/3 : FROM weaveworks/scope:1.11.2
1.11.2: Pulling from weaveworks/scope
Digest: sha256:4cdc0bac4e83f61f1675cd8fbe0709ff0df473b81977650ed3a26772ff3c627a
Status: Downloaded newer image for weaveworks/scope:1.11.2
---> d165af1c2e55
Step 2/3 : ENV http_proxy="proxy3.bj.petrochina:8080"
---> Running in e0c36494eb6b
Removing intermediate container e0c36494eb6b
---> 045d14958d3c
Step 3/3 : ENV https_proxy="proxy3.bj.petrochina:8080"
---> Running in bd51305a33de
Removing intermediate container bd51305a33de
---> a3130b788869
Successfully built a3130b788869
Successfully tagged weaveworks/scope:1.11.2
Successfully tagged weaveworks/scope:latest
docker 18.09 为我们开启了 docker的新流程 非线性构建
[root@fdfs-1 ~]# export DOCKER_BUILDKIT=1
[root@fdfs-1 ~]# docker build -t weaveworks/scope:1.11.2 -t weaveworks/scope:latest -f /tmp/Dockerfile /tmp/
[+] Building 7.1s (5/5) FINISHED
=> [internal] load .dockerignore 0.7s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.5s
=> => transferring dockerfile: 155B 0.0s
=> [internal] load metadata for docker.io/weaveworks/scope:1.11.2 4.8s
=> [1/1] FROM docker.io/weaveworks/scope:1.11.2@sha256:4cdc0bac4e83f61f1675cd8fbe0709ff0df473b81977650ed3a26772ff3c627a 0.6s
=> => resolve docker.io/weaveworks/scope:1.11.2@sha256:4cdc0bac4e83f61f1675cd8fbe0709ff0df473b81977650ed3a26772ff3c627a 0.0s
=> exporting to image 0.5s
=> => exporting layers 0.0s
=> => writing image sha256:99f9e42918a0338f08a377a1b933e331c57275326471803f591944ed414b67df 0.0s
=> => naming to docker.io/weaveworks/scope:1.11.2 0.0s
=> => naming to docker.io/weaveworks/scope:latest 0.0s
2.Parser directives
没太搞懂的概念,dockefile可以指定指令的定制器。官方指令器必须出现在dockerfile的首行,且不能换行。目前只支持syntax和escape(转义字符)
3.ENV
FROM busybox
ENV foo /bar
WORKDIR ${foo} # WORKDIR /bar
ADD . $foo # ADD . /bar
COPY \$foo /quux # COPY $foo /quux
ENV abc=hello
ENV abc=bye def=$abc
ENV ghi=$abc
will result in def having a value of hello, not bye. However, ghi will have a value of byebecause it is not part of the same instruction that set abc to bye.
ENV 中有同步定义的概念 变量赋值不分先后顺序,他们都从上一层镜像中取值,而上层镜像和本层是independence的
4.FROM
语法格式
FROM <image>[:<tag>] [AS <name>]
FROM <image>[@<digest>] [AS <name>]
5.RUN 和 CMD
RUN <command> (shell form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
RUN ["executable", "param1", "param2"] (exec form) CMD ["executable","param1","param2"] (exec form, this is the preferred form)
CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (shell form)
6.LABEL
LABEL <key>=<value> <key>=<value> <key>=<value> ...
7.EXPOSE
EXPOSE <port> [<port>/<protocol>...]
不真正暴露端口只是给使用镜像的人提供一份文档
8.COPY 和 ADD
ADD [--chown=<user>:<group>] <src>... <dest>
ADD [--chown=<user>:<group>] ["<src>",... "<dest>"] (this form is required for paths containing whitespace) --chown 只能被用于linux 容器,且如果目标容器没有这些文件/etc/passwd or /etc/group 那么本次添加也是注定失败的。 . add文件必须出现在上下文中
. src 可以是url 但url必须又 反斜杠
. add 的目标未加 / 则认为是普通文件会被复写
. add 添加压缩文件会被解压
. add 目标文件加了/ 会被认为是一个文件夹,如果这个文件正好存在,那他将被复写,非常坑爹。
COPY [--chown=<user>:<group>] <src>... <dest>
COPY [--chown=<user>:<group>] ["<src>",... "<dest>"] (this form is required for paths containing whitespace)
很温和不会帮我们自动解压
9.ENTRYPOINT
ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)
ENTRYPOINT command param1 param2 (shell form)

10.WORKDIR USER 略
11.HEALTHCHECK
HEALTHCHECK [OPTIONS] CMD command (check container health by running a command inside the container)
HEALTHCHECK NONE (disable any healthcheck inherited from the base image)
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost/ || exit 1
health check 是非常重要的
1.Dockerfile的更多相关文章
- 如何用Dockerfile创建镜像
本文原创,原文地址为:http://www.cnblogs.com/fengzheng/p/5181222.html 创建镜像的目的 首先说DockerHub或其它一些镜像仓库已经提供了够多的镜像,有 ...
- Dockerfile初探
git上的asp.net samples工程已经写好了docker file,内容是如下 //任何dockersfile都要以FORM开头,约定是用大写. FROM microsoft/aspne ...
- ubuntu 16.04 Dockerfile 安装mysql
默认上MariaDB的包并没有在Ubuntu仓库中.要安装MariaDB,我们首先要设置MariaDB仓库. 配置MariaDB 仓库 # apt-get install software-prope ...
- 分析Mysql 5.6的Dockerfile
Docker官方的Mysql镜像的Dockerfile托管在Github上,地址如下: https://github.com/docker-library/mysql/tree/5836bc9af9d ...
- 利用Dockerfile构建一个基于centos 7,包括java 8, tomcat 7,php ,mysql+mycat的镜像
Dockerfile内容如下: FROM centos MAINTAINER Victor ivictor@foxmail.com WORKDIR /root RUN rm -f /etc/yum.r ...
- Docker dockerfile创建Eclipse镜像初试
抽空初步阅读了Docker技术入门与实战 [Kindle电子书] http://www.cnblogs.com/2018/p/4600116.html 现在想首先在开发环境下引入统一的环境,由于开发中 ...
- 安装Nginx的Dockerfile实例
#################################################Dockerfile to build Nginx Installed Containers##Bas ...
- 测试dockerfile
测试dockerfile是否ok(比如我的Dockerfile在deploy目录下) docker build -t my_image -f deploy/Dockerfile . docker im ...
- 通过Dockerfile建立.NET Core mvc Image
生成.NET core mvc code docker run -itd microsoft/dotnet:latestdocker psdocker attach containeridmkdir ...
- .Net Core+cenos7+Docker+Dockerfile 部署实践
因为这段时间比较忙,同时也在抽时间将开发框架转移到 .net Core 上 所以写博客的时间就少了,这次我利用dockerfile成功将.net Core程序部署到了cenos7容器中,特抽时间把我的 ...
随机推荐
- 配置apache运行cgi程序
配置apache运行cgi程序 文章目录 [隐藏] ScriptAlias目录的CGI ScriptAlias目录以外的CGI 配置apache运行cgi程序可分为两种情况,一是ScriptAlias ...
- zip(), dict(), itertools.repeat(), list(迭代器)
*. zip(), dict() def demo_zip_dict(): keys = ['a', 'b', 'c'] values = [1, 2, 3] entrys = zip(keys, v ...
- 2019年开发App记录
Pod 制作私有库参考 https://www.jianshu.com/p/f903ecf8e882 Pod私有库的升级 改代码部分,到Example文件夹执行pod install ,修改XXX.s ...
- C# Asp.NET实现上传大文件(断点续传)
以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载. 准备文件上传的API #region 文件上传 ...
- Redis-cli相关命令
> flushdb > SELECT OK []> GET db_number (nil) []> []> flushdb OK []> SELECT OK > ...
- android 启动默认的邮件客户端,多附件的问题
目前开发的app中需要发送邮件,所以需要调用android默认的邮件客户端,并需要添加多个邮件附件,我该通过哪个组件调用默认的客户端?用什么组件来支持多个附件的电子邮件? 是通过下面的哪一个?(Int ...
- 创建maven web项目时,没有web.xml文件
1.问题:创建maven项目时,选择的是创建web-app项目,但是结果配置之后,却没有web.xml文件. 2.解决办法: ------------------------------------- ...
- shell scripts 编写基础
一.shell变量的相关用法: 变量作为被赋值的一方的时候不加$,只有在使用其值的内容的时候需要加上$,该符号可 1,变量中的单引号‘’.双引号“”“.反单引号‵`.括号().大括号{}.双括号(() ...
- andriod\iphone视频禁止全屏播放
x-webkit-airplay="true" x5-playsinline="true" webkit-playsinline="true" ...
- 《SQL Server 2012 T-SQL基础》读书笔记 - 1.背景
几个缩写的全称:Data Definition Language (DDL), Data Manipulation Language (DML), and Data Control Language ...