博客
关于我
Dockerfile的ENV替换和转义符
阅读量:173 次
发布时间:2019-02-28

本文共 3965 字,大约阅读时间需要 13 分钟。

一 Dockerfile中的ENV指令用以定义镜像的环境变量
示例如下:
RUN set -ex && apt-get update && apt-get install -y iputils-ping  
ENV PATH /usr/local/bin:$PATH  
ENV LANG C.UTF-8  
ENV TERM xterm  
ENV PYTHON_VERSION 3.5.3  
ENV name1=ping name2=on_ip  
CMD $name1 $name2  
说明:定义环境变量的同时,可以引用已经定义的环境变量。
在ENV指令中,可以直接引用如下环境变量:
HOME:用户主目录
HOSTNAME:默认容器的主机名
PATH:环境路径
TERM:默认xterm
二 由于镜像的层次文件系统,ENV定义的环境变量在后续层次中才能够被应用
示例如下:
ENV abc=hello  
ENV abc=bye def=$abc  
ENV ghi=$abc  
说明:
上述定义的结果中,def=hello,ghi=bye
三 启动容器后,在容器实例中,可以通过env命令查看环境变量
env
四 实战1
1 Dockerfile文件内容
#escape=\#thie is a DockerfileFROM busyboxENV box /helloENV a1 ${box}_a1ENV a2 $box_a1ENV a3 $boxENV a4 ${box}ENV a5 ${a1:-world}ENV a6 ${a0:-world}ENV a7 ${a1:+world}ENV a8 ${a0:+world}ENV a9 \$boxENV a10 \${box}
2 测试
[root@localhost df]# docker build -t vker/df:0.1 .Sending build context to Docker daemon  2.048kBStep 1/12 : FROM busybox---> 6ad733544a63Step 2/12 : ENV box /hello---> Running in d02799e03853---> 42ce9cb6ff2dRemoving intermediate container d02799e03853Step 3/12 : ENV a1 ${box}_a1---> Running in 2da6572101ea---> b0c48ad6493fRemoving intermediate container 2da6572101eaStep 4/12 : ENV a2 $box_a1---> Running in ecfcef134413---> 01b1c31bafebRemoving intermediate container ecfcef134413Step 5/12 : ENV a3 $box---> Running in 0b99c236d291---> c23b77d0dc2bRemoving intermediate container 0b99c236d291Step 6/12 : ENV a4 ${box}---> Running in 857f46adaa4b---> 96bc86cb4b4eRemoving intermediate container 857f46adaa4bStep 7/12 : ENV a5 ${a1:-world}---> Running in c2c28de1df9c---> 6b06e0e7e3d2Removing intermediate container c2c28de1df9cStep 8/12 : ENV a6 ${a0:-world}---> Running in d98a96c77096---> 9ee5a36f5cffRemoving intermediate container d98a96c77096Step 9/12 : ENV a7 ${a1:+world}---> Running in cccb508fea54---> 74e8b22013bcRemoving intermediate container cccb508fea54Step 10/12 : ENV a8 ${a0:+world}---> Running in ef18b0a3b373---> 6a58987ed19bRemoving intermediate container ef18b0a3b373Step 11/12 : ENV a9 \$box---> Running in 8b58200ba08e---> 98eb20ae4275Removing intermediate container 8b58200ba08eStep 12/12 : ENV a10 \${box}---> Running in e885b683320e---> 2a25e714317fRemoving intermediate container e885b683320eSuccessfully built 2a25e714317fSuccessfully tagged vker/df:0.1[root@localhost df]# docker run -it vker/df:0.1/ # envHOSTNAME=da1714f4cec7SHLVL=1HOME=/rootTERM=xterma1=/hello_a1PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bina2=a3=/helloa4=/helloa5=/hello_a1box=/helloa6=worlda7=worlda8=a9=$boxa10=${box}PWD=/
五 实战2
1 Dockerfile
#escape=`#thie is a DockerfileFROM busyboxENV box /helloENV a1 ${box}_a1ENV a2 $box_a1ENV a3 $boxENV a4 ${box}ENV a5 ${a1:-world}ENV a6 ${a0:-world}ENV a7 ${a1:+world}ENV a8 ${a0:+world}ENV a9 \$boxENV a10 \${box}
2 测试
[root@localhost df]# docker build -t vker/df:0.2 .Sending build context to Docker daemon  2.048kBStep 1/12 : FROM busybox---> 6ad733544a63Step 2/12 : ENV box /hello---> Using cache---> 42ce9cb6ff2dStep 3/12 : ENV a1 ${box}_a1---> Using cache---> b0c48ad6493fStep 4/12 : ENV a2 $box_a1---> Using cache---> 01b1c31bafebStep 5/12 : ENV a3 $box---> Using cache---> c23b77d0dc2bStep 6/12 : ENV a4 ${box}---> Using cache---> 96bc86cb4b4eStep 7/12 : ENV a5 ${a1:-world}---> Using cache---> 6b06e0e7e3d2Step 8/12 : ENV a6 ${a0:-world}---> Using cache---> 9ee5a36f5cffStep 9/12 : ENV a7 ${a1:+world}---> Using cache---> 74e8b22013bcStep 10/12 : ENV a8 ${a0:+world}---> Using cache---> 6a58987ed19bStep 11/12 : ENV a9 \$box---> Running in c9e0ec549370---> 580f54c68259Removing intermediate container c9e0ec549370Step 12/12 : ENV a10 \${box}---> Running in 10db56b4ab60---> 9d7e21bc1282Removing intermediate container 10db56b4ab60Successfully built 9d7e21bc1282Successfully tagged vker/df:0.2[root@localhost df]# docker run -it vker/df:0.2/ # envHOSTNAME=2fc25e990f12SHLVL=1HOME=/rootTERM=xterma1=/hello_a1PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bina2=a3=/helloa4=/helloa5=/hello_a1box=/helloa6=worlda7=worlda8=a9=\/helloa10=\/hello

转载地址:http://wjej.baihongyu.com/

你可能感兴趣的文章
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_根据binlog实现数据实时delete同步_实际操作04---大数据之Nifi工作笔记0043
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置binlog_使用处理器抓取binlog数据_实际操作01---大数据之Nifi工作笔记0040
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置数据路由_实现数据插入数据到目标数据库_实际操作03---大数据之Nifi工作笔记0042
查看>>
NIFI从MySql中离线读取数据再导入到MySql中_03_来吧用NIFI实现_数据分页获取功能---大数据之Nifi工作笔记0038
查看>>
NIFI从MySql中离线读取数据再导入到MySql中_无分页功能_02_转换数据_分割数据_提取JSON数据_替换拼接SQL_添加分页---大数据之Nifi工作笔记0037
查看>>
NIFI从PostGresql中离线读取数据再导入到MySql中_带有数据分页获取功能_不带分页不能用_NIFI资料太少了---大数据之Nifi工作笔记0039
查看>>
nifi使用过程-常见问题-以及入门总结---大数据之Nifi工作笔记0012
查看>>
NIFI分页获取Mysql数据_导入到Hbase中_并可通过phoenix客户端查询_含金量很高的一篇_搞了好久_实际操作05---大数据之Nifi工作笔记0045
查看>>
NIFI同步MySql数据_到SqlServer_错误_驱动程序无法通过使用安全套接字层(SSL)加密与SQL Server_Navicat连接SqlServer---大数据之Nifi工作笔记0047
查看>>
Nifi同步过程中报错create_time字段找不到_实际目标表和源表中没有这个字段---大数据之Nifi工作笔记0066
查看>>
NIFI大数据进阶_FlowFile拓扑_对FlowFile内容和属性的修改删除添加_介绍和描述_以及实际操作---大数据之Nifi工作笔记0023
查看>>
NIFI大数据进阶_NIFI的模板和组的使用-介绍和实际操作_创建组_嵌套组_模板创建下载_导入---大数据之Nifi工作笔记0022
查看>>
NIFI大数据进阶_NIFI监控的强大功能介绍_处理器面板_进程组面板_summary监控_data_provenance事件源---大数据之Nifi工作笔记0025
查看>>
NIFI大数据进阶_NIFI集群知识点_认识NIFI集群以及集群的组成部分---大数据之Nifi工作笔记0014
查看>>
NIFI大数据进阶_NIFI集群知识点_集群的断开_重连_退役_卸载_总结---大数据之Nifi工作笔记0018
查看>>
NIFI大数据进阶_内嵌ZK模式集群1_搭建过程说明---大数据之Nifi工作笔记0015
查看>>
NIFI大数据进阶_外部ZK模式集群1_实际操作搭建NIFI外部ZK模式集群---大数据之Nifi工作笔记0017
查看>>
NIFI大数据进阶_实时同步MySql的数据到Hive中去_可增量同步_实时监控MySql数据库变化_操作方法说明_01---大数据之Nifi工作笔记0033
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_01_实际操作---大数据之Nifi工作笔记0029
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_02_实际操作_splitjson处理器_puthdfs处理器_querydatabasetable处理器---大数据之Nifi工作笔记0030
查看>>