特点:类似于ansible 剧本,大小几kb
而,手动做的镜像,要几百M,甚至上G ,传输不方便
dockerfile 支持自定义容器的初始命令
dockerfile只要组成部分:
基础镜像信息 FROM centos:6.9
制作镜像操作指令 RUN yum install openssh-server -y
容器执行时初始命令 CMD ["/bin/bash","/init/sh"]
dockerfile常用指令
FROM 这个镜像的妈妈是谁?(指定基础镜像) MAINTAINER 告诉别人,谁负责养它?(指定维护者信息,可以没有) LABLE 描述,标签 RUN 你想让它干啥(在命令前面加上RUN即可) ADD 给它点创业资金(会自动解压tar) 制作docker基础的系统镜像 WORKDIR 我是cd,今天刚化了妆(设置当前工作目录) VOLUME 给它一个存放行李的地方(设置卷,挂载主机目录) EXPOSE 它要打开的门是啥(指定对外的端口)(-P 随机端口) CMD 奔跑吧,兄弟!(指定容器启动后的要干的事情)(容易被替换) dockerfile其他指令: COPY 复制文件(不会解压)rootfs.tar.gz ENV 环境变量 ENTRYPOINT 容器启动后执行的命令(无法被替换,启容器的时候指定的命令,会被当成参数)
根据dockerfile创建一个nginx容器
mkdir /opt/dockerfile/nginx -p cd /opt/dockerfile/nginx vim dockerfile ############### FROM centos:6.9 RUN echo "192.168.37.200 mirrors.aliyun.com" >>/etc/hosts RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo RUN curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo RUN yum install nginx -y WORKDIR /usr/share/nginx/html EXPOSE 80 ADD xiaoniao . CMD ["nginx","-g","daemon off;"] ############### 下载关于小鸟的代码包
根据dockerfile搭建一个可道云容器
mkdir /opt/dockerfile/kod -p cd /opt/dockerfile/kod vim dockerfile ################################### FROM centos6.9_nginx:v1 RUN yum install nginx php-fpm php-gd php-mbstring unzip -y ADD www.conf /etc/php-fpm.d/www.conf RUN gzip /etc/nginx/conf.d/* ADD kod.com.conf /etc/nginx/conf.d/kod.conf ADD init.sh /init.sh RUN mkdir /code WORKDIR /code RUN curl -o kod.zip http://192.168.37.200/191127/kodexplorer4.40.zip RUN unzip kod.zip RUN chown -R nginx:nginx . CMD ["/bin/bash","/init.sh"] ################## vim init.sh ################### #!/bin/bash /usr/sbin/php-fpm --daemonize nginx -g 'daemon off;' ################## 将手动修改完成的php配置文件,nginx配置文件上传到当前目录下 打开网页,测试容器是否创建成功 docker commit 主机id kod:v1 测试镜像 docker run -d -p 80:80 kod:v1