話很少說先上效果圖,先肯定是否是你想要達到的結果
html
##安裝編譯docker 環境
咱們這裏採用的是nginx1.16.0 版原本進行編譯安裝的,若是有須要你能夠自行更改爲別的nginx版本,Dockerfile以下linux
FROM alpine:latest AS alpine-base WORKDIR /usr/local #更換apline的源爲阿里雲的 RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories && \ echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories && \ apk update && \ #安裝wget 和git 咱們爲了使鏡像最小化這個都放在另一個鏡像裏面來實現 apk add --no-cache wget git && \ #下載nginx包 wget http://nginx.org/download/nginx-1.16.0.tar.gz && \ tar xvf nginx-1.16.0.tar.gz && \ #克隆咱們須要的模塊和主題 git clone https://github.com/Naereen/Nginx-Fancyindex-Theme.git && \ git clone https://github.com/aperezdc/ngx-fancyindex.git && \ mkdir /usr/local/nginx-1.16.0/model && \ mv ./ngx-fancyindex /usr/local/nginx-1.16.0/model/ FROM alpine:latest MAINTAINER zhangshoufu zsf18163201@163.com WORKDIR /root #從上面一個鏡像中把咱們剛纔下載安裝的包拷貝到這個裏面 COPY --from=alpine-base /usr/local/nginx-1.16.0 /usr/local/nginx-1.16.0 RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories && \ echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories && \ apk update && \ #安裝編譯安裝須要的依賴 apk add --no-cache gcc libc-dev make openssl-dev pcre-dev zlib-dev linux-headers curl && \ cd /usr/local/nginx-1.16.0/ && \ #執行編譯安裝 ./configure --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --modules-path=/usr/lib/nginx/modules \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ #指定安裝擴展模塊的位置 --add-module=/usr/local/nginx-1.16.0/model/ngx-fancyindex \ --with-compat \ --with-file-aio \ --with-threads \ --with-http_addition_module \ --with-http_auth_request_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_mp4_module \ --with-http_random_index_module \ --with-http_realip_module \ --with-http_secure_link_module \ --with-http_slice_module \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_sub_module \ --with-http_v2_module \ --with-mail \ --with-mail_ssl_module \ --with-stream --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.16.0/debian/debuild-base/nginx-1.16.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \ --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' && \ make && make install && \ mkdir -p /var/cache/nginx/client_temp && \ rm -rf /usr/local/nginx-1.16.0 #把主題拷貝到網站根目錄下 COPY --from=alpine-base /usr/local/./Nginx-Fancyindex-Theme /etc/nginx/html EXPOSE 80 CMD ["/bin/sh","-c","nginx -g 'daemon off;'"]
咱們執行構建動做nginx
docker build -t apline-nginx:v2.0 -f Dockerfile .
截止目前爲止咱們的docker 包已經構建完成了,git
由於咱們打包的docker包裏面索引主題放在了/etc/nginx/html下面,因此咱們就把網站根目錄設在這個目錄下,而後咱們經過掛載的方式把網站目錄掛載到這個目錄下,咱們先編寫nginx.conf文件github
```nginx.conf
worker_processes auto;docker
events {
worker_connections 1024;
}瀏覽器
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;bash
fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; fancyindex_header "/Nginx-Fancyindex-Theme-light/header.html"; fancyindex_footer "/Nginx-Fancyindex-Theme-light/footer.html"; fancyindex_ignore "examplefile.html"; fancyindex_ignore "Nginx-Fancyindex-Theme-light"; fancyindex_name_length 255; server { listen 80; server_name localhost; location / { autoindex on; root /etc/nginx/html; index index.html index.htm; } }
}app
由於這個裏面有兩套主題,一套黑的一套白的,咱們上面nginx配置文件使用的是白色的主題,若是咱們想使用黑色的只須要把配置文件裏面的`Nginx-Fancyindex-Theme-light`更換成`Nginx-Fancyindex-Theme-dark`便可。 而後咱們如今開始啓動這個docker 容器 ```bash docker run -id --name voice_nginx -p 9999:80 -v /home/monitor/:/etc/nginx/html/monitor -v /home/monitor/nginx.conf:/etc/nginx/nginx.conf --restart=always apline-nginx:v2.0
啓動完成以後咱們就能夠在瀏覽器裏面打開看到咱們想要的界面了
dom