docker部署springboot前后端分离项目(jdk+jar包+mysql+redis+nginx)
,
1.vim jdk-dockerfile
FROM centos:7
MAINTAINER sinvie.cn
WORKDIR /usr
RUN mkdir /usr/local/java
ADD jdk-8u221-linux-x64.tar.gz /usr/local/java/
ENV JAVA_HOME /usr/local/java/jdk1.8.0_221
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/bin/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV 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:latest
MAINTAINER sinvie.cn
ADD ScgService.jar /root/ScgService.jar
ENTRYPOINT ["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/conf
mkdir /usr/local/docker/nginx/html
mkdir /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/conf
mkdir /usr/local/docker/mysql57/html
mkdir /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/conf
mkdir /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