vim Dockerfile
新生成的镜像是基于sshd:dockerfile镜像
FROM sshd-centos
MAINTAINER by cmzsteven
WORKDIR /usr/local/src
安装wget
RUN yum install -y wget
下载并解压源码包
RUN wget http://nginx.org/download/nginx-1.12.1.tar.gz
RUN tar zxvf nginx-1.12.1.tar.gz
WORKDIR nginx-1.12.1
编译安装nginx
RUN yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl*
RUN useradd -M -u 40 -s /sbin/nologin nginx
RUN ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module --with-http_realip_module
RUN make
RUN make install
启动Nginx服务
RUN ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
RUN /usr/local/nginx/sbin/nginx
修改Nginx配置文件,以非daemon方式启动
RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf
复制服务启动脚本并设置权限
ADD run.sh /usr/local/sbin/run.sh
RUN chmod 755 /usr/local/sbin/run.sh
设置生成容器时需要执行的脚本
CMD ["/usr/local/sbin/run.sh"]
开放80端口
EXPOSE 80
vim run.sh
!/bin/bash
/usr/local/nginx/sbin/nginx
docker build -t nginx_dockerfile:centos .
参考
https://blog.csdn.net/qq_33285112/article/details/78593647
https://blog.csdn.net/shenzhen_zsw/article/details/74616917
网友评论