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服務(wù)
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
復(fù)制服務(wù)啟動腳本并設(shè)置權(quán)限
ADD run.sh /usr/local/sbin/run.sh
RUN chmod 755 /usr/local/sbin/run.sh
設(shè)置生成容器時需要執(zhí)行的腳本
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