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路径是否输入正确,也就是说你的项目没有准确复制到程序运行目录。
就这样,有问题留言,只要我看到并且我了解的一定回复!