docker部署springboot前后端分离项目(jdk+jar包+mysql+redis+nginx)

jdk1.8dockerfile文件

1.vim jdk-dockerfile

?FROM centos:7MAINTAINER sinvie.cnWORKDIR /usrRUN mkdir /usr/local/javaADD jdk-8u221-linux-x64.tar.gz /usr/local/java/ENV JAVA_HOME /usr/local/java/jdk1.8.0_221ENV JRE_HOME $JAVA_HOME/jreENV CLASSPATH $JAVA_HOME/bin/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATHENV PATH $JAVA_HOME/bin:$PATH?

2.运行dockerfile,构建jdk1.8镜像

docker build -f /usr/local/docker/dockerjdk18/jdk-dockerfile -t jdk1.8

springboot项目,dockerfile文件

1.vim scgservice-dockerfile

FROM jdk1.8:latestMAINTAINER sinvie.cnADD ScgService.jar /root/ScgService.jarENTRYPOINT ["nohup","java","-jar","/root/ScgService.jar","&"]

2.运行dockerfile,构建scg镜像

docker build -f /usr/local/docker/soc/scgservice-dockerfile -t scgservice

3.运行scg镜像,创建scg容器

docker run -id --name=scg -p 8888:8888 -v $PWD/logs:/root/scgService-log scgservice /bin/bash

安装nginx

1.创建容器与主机挂载的目录,挂载成功后,前端的静态项目要放在html目录下

mkdir /usr/local/docker/nginx/confmkdir /usr/local/docker/nginx/htmlmkdir /usr/local/docker/nginx/logs

2.把nginx.conf 扔到 /usr/local/docker/nginx/conf 目录,到官网下载

。。。

3.拉取镜像

docker pull nginx

4.运行nginx镜像

docker run --name nginx -d -p 80:80 -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/html:/etc/nginx/html -v $PWD/logs:/var/log/nginx nginx

安装mysql

1.创建容器与主机挂载的目录

mkdir /usr/local/docker/mysql57/confmkdir /usr/local/docker/mysql57/htmlmkdir /usr/local/docker/mysql57/logs

2.把my.cnf 扔到 /usr/local/docker/mysql57/conf 目录,到官网下载

。。。

3.拉取镜像

docker pull mysql:5.7.30

4.运行mysql镜像

docker run -id -p 3306:3306 --name=mysql57 -v $PWD/conf/my.cnf:/etc/mysql/my.cnf -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.30

安装redis

1.创建容器与主机挂载的目录

mkdir /usr/local/docker/redis50/confmkdir /usr/local/docker/redis50/data

2.把redis.conf 扔到 /usr/local/docker/redis50/conf 目录,到官网下载

。。。

3.拉取镜像

docker pull redis:5.0

4.运行redis镜像

docker run -id --name=redis50 -p 6379:6379 -v $PWD/data:/data -v $PWD/conf/redis.conf:/etc/redis/redis.conf redis:5.0