Dcoekr 部署前后端分离项目SpringBoot +Vue

1.docker 部署vue

docker 安装 nginx的镜像

niginx 配置文件
nginx.conf
 
#user  nobody;
worker_processes  1;
 
#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;
 
    server {
        listen       9090;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   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;
        }
 
        # 配置代理,解决跨域问题
        location ^~ /api/ {
            proxy_set_header Host $host;
            proxy_set_header  X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://X.X.X.X:7777/;
        }
 
        # 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;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}

docker 安装nginx ,并运行挂载主机

1.创建挂载目录
mkdir -p /home/nginx/conf
mkdir -p /home/nginx/log
mkdir -p /home/nginx/html
2.执行容器

# 生成容器
docker run --name=nginx -p 9001:80 -d nginx
# 将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf
# 将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d
# 将容器中的html文件夹复制到宿主机
docker cp nginx:/usr/share/nginx/html /home/nginx/
3.挂载完成后删除重启
# 直接执行docker rm nginx或者以容器id方式关闭容器
# 找到nginx对应的容器id
docker ps -a
# 关闭该容器
docker stop nginx
# 删除该容器
docker rm nginx
 
# 删除正在运行的nginx容器
docker rm -f nginx
4.重启
docker run \
-p 9002:80 \
--name nginx \
-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/nginx/log:/var/log/nginx \
-v /home/nginx/html:/usr/share/nginx/html \
-d nginx:latest

启动后可以发现nginx容器是功能减少版的linux,其中丢失了vi等函数,所以只能通过挂载的形式,让宿主机影响容器.
在这里插入图片描述
只需要查看宿主数据卷的文件即可,可以删除容器了

配值dockerfile

# 基础镜像使用Nginx
FROM nginx
# 作者
MAINTAINER hou
# 添加时区环境变量,亚洲,上海
ENV TimeZone=Asia/Shanghai    
# 使用软连接,并且将时区配置覆盖/etc/timezone
RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone
# 将前端dist文件中的内容复制到容器内nginx目录
COPY dist/  /etc/nginx/html/
# 覆盖镜像的Nginx配置
COPY nginx.conf /etc/nginx/nginx.conf

#输出完成
RUN echo 'echo init ok!!'

此时三个文件在同一目录
在这里插入图片描述

  1. 然后build 为镜像 docker build -f (当前路径)./xxdockerfile -t 镜像名 .
docker run --name=nginx -p 9001:80 -d nginx
  1. docker run -id --name=project-vue -p 9876:9876 qianduanimage(镜像)
2.docker 部署springboot项目

1.需求:

​ 定义dockerfile,发布springboot 项目

实现步骤:
和你的后盾jar包同一目录新建Dockerfile

FROM java:8
MAINTAINER hou 
ADD springboot.jar  app.jar
CMD java -jar  app.jar

此时目录(我这里jar包就叫app,需要上面的springboot.jar 需要根据你的包名来)
在这里插入图片描述

  1. 定义父镜像:FROM java:8
  2. 定义作者信息:MAINTAINER hou <www.crisp077.xyz>
  3. 将jar包添加到容器且重命名:ADD springboot.jar app.jar
  4. 定义容器启动执行的命令:CMD java -jar app.jar
  5. 通过dockerfile 构建镜像:docker build -f dockerfile文件路径 -t 镜像名称:版本 .(注意这里有个点)
  6. 构建
docker build -f   ./Dockerfile    -t  app .
  1. 运行
docker run -id --name=houuduan  -p 80:800   镜像名字

其中

  • -p 外接口:镜像接口 docker 这里指的是项目80端口 外映射到服务器

  • 80:映射到的外联端口

  • 800:镜像项目的端口

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝胖子不是胖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值