Dockerfile 基本结构
2018-03-07 11:16
405 查看
基本结构
Dockerfile 由一行行命令语句组成,并且支持以#开头的注释行。一般的,Dockerfile 分为四部分:基础镜像信息、维护者信息、镜像操作指令和容器启动时执行指令。例如
# This dockerfile uses the ubuntu image # VERSION 2 - EDITION 1 # Author: docker_user # Command format: Instruction [arguments / command] .. # Base image to use, this must be set as the first line FROM ubuntu # Maintainer: docker_user <docker_user at email.com> (@docker_user) MAINTAINER docker_user docker_user@email.com # Commands to update the image RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list RUN apt-get update && apt-get install -y nginx RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf # Commands when creating a new container CMD /usr/sbin/nginx其中,一开始必须指明所基于的镜像名称,接下来推荐说明维护者信息。后面则是镜像操作指令,例如
RUN指令,
RUN指令将对镜像执行跟随的命令。每运行一条
RUN指令,镜像添加新的一层,并提交。最后是
CMD指令,来指定运行容器时的操作命令。下面是一个更复杂的例子
# Nginx # # VERSION 0.0.1 FROM ubuntu MAINTAINER Victor Vieux <victor@docker.com> RUN apt-get update && apt-get install -y inotify-tools nginx apache2 openssh-server # Firefox over VNC # # VERSION 0.3 FROM ubuntu # Install vnc, xvfb in order to create a 'fake' display and firefox RUN apt-get update && apt-get install -y x11vnc xvfb firefox RUN mkdir /.vnc # Setup a password RUN x11vnc -storepasswd 1234 ~/.vnc/passwd # Autostart firefox (might not be the best way, but it does the trick) RUN bash -c 'echo "firefox" >> /.bashrc' EXPOSE 5900 CMD ["x11vnc", "-forever", "-usepw", "-create"] # Multiple images example # # VERSION 0.1 FROM ubuntu RUN echo foo > bar # Will output something like ===> 907ad6c2736f FROM ubuntu RUN echo moo > oink # Will output something like ===> 695d7793cbe4 # You᾿ll now have two images, 907ad6c2736f with /bar, and 695d7793cbe4 with # /oink.
相关文章推荐
- Dockerfile基本语法结构和指令用法详解
- Dockerfile基本结构及基本指令
- Dockerfile基本语法
- Docker的基本命令和Dockerfile的指令
- DockerFile实战(二):DockerFile编写要求与基本风格
- Dockerfile 指令和结构
- 【Dockerfile】CentOS6.x中Docker通过Dockerfile构建常用的基础环境 # 设置基本的镜像,后续命令都以这个镜像为基础 FROM centos # 作者信息 MAI
- Docker基本命令与使用 —— Dockerfile指令与构建(三)
- 毕业设计预习:VHDL入门知识学习(一) VHDL程序基本结构
- Java基础——对象序列化+管道流+RandomAccessFile+操作基本数据类型的DataStream等
- File类基本操作之OutputStream字节输出流
- 迎接2012之集合和泛型(3)------栈的顺序结构基本实现
- HighCharts的基本组成结构分析
- 解剖Nginx·模块开发篇(2)ngx_http_hello_world_module 模块基本结构定义
- 深入理解JVM(一)------基本结构
- 链栈的基本操作-数据结构
- PHP扩展的基本结构
- SkinUI入门教程(二) SkinUI应用程序的基本结构
- 线性表链式存储结构基本操作