Linux下使用docker部署前後分離netcore webapi項目、前端vue頁面、Mysql、Redis、SQLite
Linux下使用docker部署netcore(一)
Linux下使用docker部署Mysql(二)
Linux下使用docker部署Redis(三)
Linux下使用docker部署發佈後的netcore(四)
Linux下使用docker部署VUE(五)
說明
這篇文章是爲了記錄公司的項目部署過程,方便給其他運維人員查閱,我對linux的詳細操作談不上非常精通,如果只是想了解實戰項目的部署流程可以查看這篇文章。本文介紹了linux下使用docker的基本操作、使用docker部署netcore webapi項目、vue項目、Mysql、Redis、SQLite。我們先是一步一步部署,之後會採用docker-compose一步生成多種環境。 本人能力有限,底層的東西講不清楚,但是會把遇到的問題的解決辦法分享出來供大家查閱。廢話不多說,直接整。
需要的文件
- vue編譯後的dist文件
- Dockerfile文件(自己創建)
# 設置基礎鏡像
FROM nginx
# 定義作者
MAINTAINER longdb
# 將dist文件中的內容複製到 /usr/share/nginx/html/ 這個目錄下面
COPY dist/ /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/nginx.conf
RUN echo 'echo init ok!!'
- nginx.conf(自己創建)
worker_processes auto;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
client_max_body_size 20m;
server {
listen 80;
server_name www.longdb.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
接下來將這三個東西複製到服務器中
創建鏡像:
docker build -t nginx:v1 .
使用docker images查看是否生成成功。
生成容器:
docker run --name vuedatavisual -p 8000:8000 -d nginx:v1
使用docker ps -a查看STATUS查看是否是Up狀態,Up代表運行成功。
接下來就輸入ip加端口號訪問我們的網站吧。
我之前遇到一個問題,鏡像也生成了,容器也是Up狀態了,但是每次訪問地址的時候網頁都是說Welcome to nginx!出現這個問題請檢查Dockerfile文件裏Copy路徑是否輸入正確,也就是說你的項目沒有準確複製到程序運行目錄。
就這樣,有問題留言,只要我看到並且我瞭解的一定回覆!