1. 程式人生 > >【容器技術】Docker映象 + nginx 部署Vue專案

【容器技術】Docker映象 + nginx 部署Vue專案

如果使用docker部署思維要做轉變,

以前:啟動nginx或者tomcat,把打包的war或者是靜態html丟在web伺服器專案工程資料夾下

現在:專案還有專案需要依賴的tomact,nginx,還有其他環境,甚至是作業系統,其他等等,全部製作成一個映象,任何一臺電腦,只要安裝了docker,都能直接執行這個映象,釋出你自己的工程,完全獨立的虛擬環境

現在就以vue專案為例,基於docker映象釋出工程

由於vue編譯過後是一段靜態html的檔案,要想使用,必須執行在http伺服器(nginx,tomact,httpServer等等),本文就以nginx作為http伺服器


六步走流程說明
第一步:vue專案打包 

node build/build.js 生成檔案格式如圖


第二步:同目錄下建立資料夾 Dockerfile,內容如下

#匯入nginx映象FROM nginx:1.13.7MAINTAINER Guang Zhouguang <[email protected]>#把當前打包工程的html複製到虛擬地址
ADD ./app /usr/share/nginx/html#使用自定義nginx.conf配置埠和監聽
COPY nginx.conf /etc/nginx/nginx.confRUN /bin/bash -c 'echo init ok!!!'
第三步:建立nginx.config
worker_processes auto;
#pid /usr/local/nginx/logs/nginx.pid;#error_log /usr/local/nginx/logs/error.log crit;worker_rlimit_nofile 1000000;
events { worker_connections 65536; multi_accept on; use epoll;}
http { include mime.types; default_type application/octet-stream;
sendfile on; tcp_nopush on;
tcp_nodelay on; server_tokens off;
keepalive_timeout 10; client_header_timeout 10; client_body_timeout 10; reset_timedout_connection on; send_timeout 10;
limit_conn_zone $binary_remote_addr zone=addr:5m; limit_conn addr 100;
gzip on; gzip_disable "msie6" gzip_static on; gzip_proxied any; gzip_min_length 1000; gzip_comp_level 4; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
open_file_cache max=100000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on;
# include /etc/nginx/conf.d/*.conf; # include /etc/nginx/sites-enabled/*;
server { listen 80; # 介面服務的IP地址 server_name localhost; charset utf-8; access_log off; # ElecManageSystem-應用資料夾名稱 app-index.html頁面所在資料夾 root /usr/share/nginx/html; location / { index index.html index.htm; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}
第四步:製作映象 docker build -t rb:1 .



第五步:檢視映象(docker images),rb就是剛才建立的映象了  




好了,這裡映象就執行成功了,接下來就可以執行映象了,不管推送到哪兒,都可以直接用了,方便吧?

第六步:執行映象



可以根據容器id 檢視啟動日誌 

docker logs d377fea6caa9