docker--在centos镜像上添加其他镜像

一句话总结:镜像分层,可一层层叠加,关键是Dockerfile的编写

Dockerfile:

#新生成的镜像是基于sshd:dockerfile镜像
From docker.io/centos
MAINTAINER simon "[email protected]"
RUN cd /usr/local/src     #或者使用:WORKDIR /usr/local/src
RUN yum install -y wget
#脚本安装Nginx,与在centos安装一样
RUN wget http://nginx.org/download/nginx-1.15.0.tar.gz
RUN tar -zxvf nginx-1.15.0.tar.gz
WORKDIR nginx-1.15.0
#安装第三方库
RUN yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
RUN yum -y install pcre-devel
RUN ./configure --prefix=/usr/local/nginx   --with-pcre
RUN make
RUN make install
#启动Nginx服务
RUN /usr/local/nginx/sbin/nginx
ADD run.sh /usr/local/sbin/run.sh
RUN chmod +x /usr/local/sbin/run.sh
#设置生成容器时需要执行的脚本
CMD ["/usr/local/sbin/run.sh"]
#开放22(ssh)、80、443(Nginx默认)端口
EXPOSE 22
EXPOSE 80
EXPOSE 443

备注:在Dockerfile文件中更换当前目录RUN cd nginx-1.15.0没有作用,改用WORKDIR nginx-1.15.0正常.

run.sh:

#!/bin/bash
/usr/sbin/sshd
/usr/local/nginx/sbin/nginx

你可能感兴趣的:(docker)