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.7
MAINTAINER Guang Zhouguang <[email protected]>
#把當前打包工程的html複製到虛擬地址
ADD ./app /usr/share/nginx/html
#使用自定義nginx.conf配置端口和監聽
COPY nginx.conf /etc/nginx/nginx.conf

RUN /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
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章