dockerfile automatically create docker mirror

Features: ansible similar script, several kb size
and, to do a manual mirror M to hundreds, or even G, convenient transfer

dockerfile support custom container initial command

dockerfile long components:
the base image information FROM centos: 6.9
to mirror the operation instruction RUN yum install openssh-server -y
container initial command performs the CMD [ "/ bin / the bash", "/ the init / SH"]
dockerfile common commands

FROM 这个镜像的妈妈是谁?(指定基础镜像)
MAINTAINER 告诉别人,谁负责养它?(指定维护者信息,可以没有)
LABLE 描述,标签
RUN 你想让它干啥(在命令前面加上RUN即可)
ADD 给它点创业资金(会自动解压tar) 制作docker基础的系统镜像
WORKDIR 我是cd,今天刚化了妆(设置当前工作目录)
VOLUME 给它一个存放行李的地方(设置卷,挂载主机目录)
EXPOSE 它要打开的门是啥(指定对外的端口)(-P 随机端口)
CMD 奔跑吧,兄弟!(指定容器启动后的要干的事情)(容易被替换)

dockerfile其他指令: 
COPY 复制文件(不会解压)rootfs.tar.gz
ENV 环境变量
ENTRYPOINT 容器启动后执行的命令(无法被替换,启容器的时候指定的命令,会被当成参数)

According to dockerfile create a container 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;"]

###############
下载关于小鸟的代码包

The channel may be a build dockerfile cloud container

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  

Guess you like

Origin www.cnblogs.com/yangxiaoni/p/11985536.html