Environment to prepare

  • Server environment:
Docker, Docker-compose install and configure the following environment: Docker, docker-composeCopy the code
  • Example code:renren-fast
The front-end project address: https://gitee.com/renrenio/renren-fast-vue.git backend project address: https://gitee.com/renrenio/renren-fast.git note: node - sass rely on download, ` node Js ` use 12 the following version "node - sass" : "4.14.1"Copy the code

Compile the project

  • Renren-fast-vue: Run the following commands in sequence to generate the dist directory

    NPM run dev # build production environment NPM run build --prodCopy the code
  • Renren-fast: Maven builds jar packages

    mvn clean package -Dmaven.test.skip=true
    Copy the code

Dockerfileconfiguration

  • renren-fast-vue

    nginxConfiguration:renren-fast-vue.conf

    server { listen 80; server_name localhost; Dist file (root /data/); location /renren-fast { proxy_pass http://renren-fast:8080; #proxy_set_header Host $http_host; proxy_connect_timeout 15s; proxy_send_timeout 15s; proxy_read_timeout 15s; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 2m; }}Copy the code

    Dockerfile:

    The FROM nginx MAINTAINER "Scorpio < [email protected] >" # set time zone RUN ln - sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime RUN echo 'Asia/Shanghai' >/etc/timezone COPY ./dist /data RUN rm /etc/nginx/conf.d/default.conf COPY renren-fast-vue.conf /etc/nginx/conf.d/ RUN /bin/bash -c 'echo vue UI init ok'Copy the code
  • renren-fast

    application-dev.yml:

    spring: datasource: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: Com. Mysql. Cj, JDBC Driver url: JDBC: mysql: / / ${3306} MYSQL_SERVER: 127.0.0.1: / renren_fast? useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: ${MYSQL_USER:root} password: ${MYSQL_PASSWORD:123456} initial-size: 10 max-active: 100 min-idle: 10 max-wait: 60000 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 time-between-eviction-runs-millis: #validation-query: SELECT 1 FROM DUAL test-while-idle: SELECT 1 FROM DUAL test-while-idle: SELECT 1 FROM DUAL test-while-idle: SELECT 1 FROM DUAL test-while-idle: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: false test-on-return: false stat-view-servlet: enabled: true url-pattern: /druid/* #login-username: admin #login-password: admin filter: stat: log-slow-sql: true slow-sql-millis: 1000 merge-sql: false wall: config: multi-statement-allow: trueCopy the code

    Dockerfile:

    The FROM Java: 8 MAINTAINER "Scorpio < [email protected] >" # set time zone RUN ln - sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime RUN Echo 'Asia/Shanghai' >/etc/timezone Set the environment variable ENV JAVA_OPTS="" \ MYSQL_SERVER="" \ MYSQL_USER="" \ MYSQL_PASSWORD="" COPY renren-fast.jar app.jar CMD java $JAVA_OPTS -jar app.jarCopy the code

Docker – compose configuration

Docker build local image:

# note: Docker-compose automatically builds an image when it starts up, # build docker build-t /home/ Scorpio /renren-fast/renren-fast-vue. # build docker build-t/Scorpio /renren-fast-vue /home/scorpio/renren-fast/renren-fast .Copy the code

docker-compose.yml:

Version: '3' services: # database renren-mysql: image: mysql:5.7 container_name: renren-mysql restart: always ports: - "3306:3306" volumes: # mysql data file - / home/docker/mysql/data: / var/lib/mysql - # mysql configuration file/home/docker/mysql/config: / etc/mysql/conf. D Environment: TZ: Asia/Shanghai # MYSQL_ROOT_PASSWORD: avit123 # renren-fast: build: context: ./renren-fast environment: MYSQL_SERVER: renren-mysql:3306 MYSQL_USER: root MYSQL_PASSWORD: avit123 JAVA_OPTS: "-server -XX:+UseG1GC -Xmx2g -XX:MaxGCPauseMillis=200 -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=logs/java_heapdump.hprof -XX:-UseLargePages -Xloggc:logs/gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M" container_name: renren-fast image: renren-fast restart: always ports: Renren-fast-vue: build: context:./renren-fast-vue restart: always container_name: renren-fast-vue image: renren-fast-vue ports: - "8001:8001"Copy the code

Project deployment

[root@3 Scorpio]# Heavy Metal Guitar School - heavy Metal Guitar School - Heavy metal Flag - Heavy metal Flag - Heavy metal Flag - Heavy metal Flag - Heavy metal Flag └ ─ ─ renren - fast. Jar └ ─ ─ renren - fast - vue ├ ─ ─ dist ├ ─ ─ Dockerfile └ ─ ─ renren - fast - vue. Conf # start the database, Docker-compose up -d renren-mysql # docker-compose up -d docker-compose up -dCopy the code

\