1、進入容器查看當前編譯安裝插件
nginx -V
--prefix=/etc//nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log --add-module=../nginx-njs/njs-0.4.2/nginx --with-http_ssl_module \
--with-pcre --with-ipv6 --with-stream --with-http_auth_request_module --with-http_sub_module \
--with-http_stub_status_module --with-http_v2_module
2、下載njs模塊
git地址:https://github.com/nginx/njs.git
yum -y install git cd /usr/local/nginx-njs git clone https://github.com/nginx/njs.git
3、在 本地編譯安裝nginx
#下載nginx源碼包: wget http://nginx.org/download/nginx-1.21.6.tar.gz # 解壓 tar zxf nginx-1.21.6.tar.gz -C /usr/local/ # 編譯安裝 ./configure --prefix=/etc//nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --add-module=../nginx-njs/njs/nginx --with-http_ssl_module --with-pcre --with-ipv6 --with-stream --with-http_auth_request_module --with-http_sub_module --with-http_stub_status_module --with-http_v2_module
make && make install
# 查看安裝是否成功
[root@localhost nginx-photon]# nginx -V
nginx version: nginx/1.21.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc//nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --add-module=../nginx-njs/njs/nginx --with-http_ssl_module --with-pcre --with-ipv6 --with-stream --with-http_auth_request_module --with-http_sub_module --with-http_stub_status_module --with-http_v2_module
[root@localhost nginx-photon]# which nginx
/usr/sbin/nginx
4、准備查找nginx1.21.6依賴庫並移動到Dockerfile所在文件夾中
find / -name libssl.so.1.1 exec cp {} /root/nginx-photon/ \; find / -name libssl.so.10 exec cp {} /root/nginx-photon/ \;
find / -name libcrypto.so.10 exec cp {} /root/nginx-photon/ \;
cp /usr/sbin/nginx /root/nginx-photon/
5、編輯Dockerfile
基礎鏡像下載地址:(https://hub.docker.com/r/goharbor/nginx-photon)
FROM goharbor/nginx-photon:v1.10.0 USER root COPY nginx /usr/sbin/nginx COPY libssl.so.10 /usr/lib64/libssl.so.10 COPY libcrypto.so.10 /usr/lib64/libcrypto.so.10 RUN chmod a+x /usr/sbin/nginx RUN chown nginx:nginx /usr/sbin/nginx USER nginx
6、打包生成鏡像
docker build -t nginx-photon:zk01 .
docker save nginx-photon:zk01 > nginx-photon.tar
7、上傳至harbor服務器所在機器后載入鏡像
docker load -i nginx-photon:zk01
8、修改docker-compose配置文件中nginx-photon鏡像版本並重啟鏡像
docker-compose up