使用Dockerfile構(gòu)建nginx-docker鏡像

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容