首页 > 数据库 >dockerfile部署vue+springboot+redis

dockerfile部署vue+springboot+redis

时间:2023-03-24 12:03:06浏览次数:39  
标签:index vue log redis nginx html error dockerfile

后端部署:

一、拉取并启动redis镜像

1、在服务器/usr/local/etc/redis/文件目录下建立redis.conf配置文件,配置信息如下:

bind 0.0.0.0
protected-mode no

2、拉取并启动最新的redis镜像,映射宿主机端口并挂载目录

docker run -p 6379:6379 --name redis -v /redis/redis.conf:/usr/local/etc/redis/redis.conf -v /redis/data:/data -d redis redis-server /usr/local/etc/redis/redis.conf

二、制作并启动后端镜像

1、修改springboot项目配置文件中redis的ip地址和端口号

 

2、新建后端的Dockerfile文件,修改端口号,端口号需要和后端项目端口号保持一致,Dockerfile内容如下:

# 指定基础镜像
# amd架构:FROM java:8 
# arm架构:FROM openjdk:8-jdk
FROM openjdk:8-jdk
# 定义匿名卷
VOLUME /tmp
#复制文件或修改名称
ADD ksource-platform.jar app.jar
# 允许指定的端口
EXPOSE 8087
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

 

3、将后端的Dockerfile文件与springboot项目的jar包放在同一个目录下

4、制作后端镜像

进入该目录执行以下命令:

docker build -t ksource-platform .

5、启动镜像生成容器

docker run -d -p 8087:8087 3f57165bbf29
1、-d参数是让容器后台运行 
2、-p 是做端口映射,此时将服务器中的8086端口映射到容器中的8087(项目中端口配置的是8087)端口
3、使用images镜像的IMAGE ID

6、访问后端地址

前端部署

一、新建nginx.conf配置文件并修改相关配置

新建nginx配置文件,并修改ip地址和端口号

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       3000;
        server_name  10.65.12.75;
  
        #charset koi8-r;
  
        #access_log  logs/host.access.log  main;
     location / {
        root   /usr/local/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;
    #    }
    #}
  
}

二、制作并启动前端镜像

1、新建前端Dockerfile文件

新建Dockerfile文件,将以下内容复制进去

# 设置基础镜像
FROM nginx
# 将dist文件中的内容复制到 /usr/local/nginx/html 这个目录下面
COPY dist/  /usr/local/nginx/html
RUN chmod -R 755 /usr/local/nginx/html
COPY nginx.conf  /etc/nginx/nginx.conf
RUN echo 'ok!!'

2、将上面新建的nginx.conf文件和前端的Dockerfile文件以及前端vue打的包dist文件夹放在同一目录下

3、制作前端镜像

进入该目录执行以下命令:

 docker build -t query-web .

4、启动容器

docker  run  --privileged  -it  -d  --name  web  -p  3000:3000  query-web

执行完后可以通过命令:docker ps -a查看容器启动状态

标签:index,vue,log,redis,nginx,html,error,dockerfile
From: https://www.cnblogs.com/henuyuxiang/p/17250264.html

相关文章

  • Docker - dockerfile as 关键字
    在Dockerfile中使用AS(或as)关键字可以创建一个多阶段构建(multi-stagebuild)。多阶段构建是一种将应用程序的构建过程分解为多个阶段(stage)的技术,每个阶段使用不同的基础......
  • Vue.js 路由简介
    路由理解:一个路由(route)就是一组映射关系(key-value),多个路由需要路由器(router)进行管理。前端路由:key是路径,value是组件。......
  • Vuex 和 localStorage 的区别
    Vuex和localStorage的区别最重要的区别:vuex存储在内存中localstorage则以文件的方式存储在本地,只能存储字符串类型的数据,存储对象需要JSON的stringify和parse方......
  • javaweb——使用axios和vue改造书城项目的购物车
    资料来源于:B站尚硅谷JavaWeb教程(全新技术栈,全程实战),本人才疏学浅,记录笔记以供日后回顾由于是多个视频内容混合在一起,因此只放了第一个链接视频链接代码示例index......
  • vue3组件之间传值
    父组件向子组件传值1.简单的props方式//fater.vue<divclass="father"><children:carr="arr"/></div><scriptsetuplang="ts">importchildrenfrom'./......
  • 什么是redis
    一、redis简介Redis是C语言开发的一个开源高性能键值对的内存数据库,可以用来做数据库、缓存、消息中间件等场景,是一种NoSQL(not-onlysql,非关系型数据库)的数据库二、R......
  • vue export学习笔记2
    #创建项目vuecreatevuecli-dem0#启动项目npmrunserve#打包项目npmrunbuild#路由说明由于Vue在开发时对路由支持的不足,于是官方补充了vue-router插件。vue的单......
  • Vue3中使用pinia
    Vue3中使用piniaPinia是一个轻量级的、基于Vue3的状态管理库,它的设计目标是提供简单易用的API,使得开发者能够更加便捷地管理Vue3应用程序中的状态。与Vuex相比,Pinia更加......
  • vue export学习笔记
    export用来导出模块,Vue的单文件组件通常需要导出一个对象,这个对象是Vue实例的选项对象,以便于在其它地方可以使用import引入。export和exportdefault的区别在于:e......
  • Vue.js Vuex实现求和案例
    视频Vuex版本componentsCount.vue<template> <div> <!--模板里能看见vc上所有东西--> <h1>当前求和为:{{$store.state.sum}}</h1> <selectv-model.number="n......