![关注抖音创业](https://img.kancloud.cn/c5/ce/c5ced2ea291122851697114ca415ff95_1125x1680.png) [TOC] > spring boot mybatis源码地址 [源码](https://github.com/taot168/springboot-mybatis02) # MySQL容器 > (1)创建volume ``` docker volume create v1 ``` > (2)创建mysql容器 ``` docker run -d --name my-mysql -v v1:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --net=pro-net --ip 172.16.0.6 mysql ``` > (3)datagrip连接,执行.mysql文件 ``` name:my-mysql ip:centos-ip 端口:3306 user:root password:123456 ``` ```sql create schema db_docker_springboot collate utf8_general_ci; use db_docker_springboot; CREATE TABLE `t_user` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `username` VARCHAR(50) NOT NULL, `password` VARCHAR(50) NOT NULL, `number` VARCHAR(100) NOT NULL, PRIMARY KEY (`id`) ) COLLATE='utf8_general_ci' ENGINE=InnoDB ; ``` # Spring Boot项目准备 > Spring Boot+MyBatis实现CRUD操作,名称为“springboot-mybatis” ``` (1)在本地测试该项目的功能 主要是修改application.yml文件中数据库的相关配置 (2)在项目根目录下执行mvn clean package打成一个jar包 [记得修改一下application.yml文件数据库配置] mvn clean package -Dmaven.test.skip=true 在target下找到"springboot-mybatis-0.0.1-SNAPSHOT.jar" (3)在docker环境中新建一个目录"springboot-mybatis" (4)安装文件传输工具yum install lrzsz,然后上传"springboot-mybatis-0.0.1-SNAPSHOT.jar"到该目录下,并且在此目录创建Dockerfile (5)编写Dockerfile内容 FROM openjdk:8 MAINTAINER pm LABEL name="springboot-mybatis" version="1.0" author="pm" COPY springboot-mybatis-0.0.1-SNAPSHOT.jar springboot-mybatis.jar CMD ["java","-jar","springboot-mybatis.jar"] (6)基于Dockerfile构建镜像 docker build -t sbm-image . (7)基于image创建container docker run -d --name sb01 -p 8081:8080 --net=pro-net --ip 172.16.0.11 sbm-image (8)查看启动日志docker logs sb01 (9)在win浏览器访问http://192.168.136.200:8081/user/listall ``` # 创建多个项目容器 ``` docker run -d --name sb01 -p 8081:8080 --net=pro-net --ip 172.16.0.11 sbm-image docker run -d --name sb02 -p 8082:8080 --net=pro-net --ip 172.16.0.12 sbm-image docker run -d --name sb03 -p 8083:8080 --net=pro-net --ip 172.16.0.13 sbm-image ``` # Nginx > (1)在centos的/tmp/nginx下新建nginx.conf文件,并进行相应的配置 ``` user nginx; worker_processes 1; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; location / { proxy_pass http://upstream; } } upstream upstream{ server 172.16.0.11:8080; server 172.16.0.12:8080; server 172.16.0.13:8080; } include /etc/nginx/conf.d/*.conf; } ``` > (2)创建nginx容器 > > `注意`:先在centos7上创建/tmp/nginx目录,并且创建nginx.conf文件,写上内容 ``` docker run -d --name my-nginx -p 80:80 -v /tmp/nginx/nginx.conf:/etc/nginx/nginx.conf --network=pro-net --ip 172.16.0.10 nginx ``` > (3)win浏览器访问: ip[centos]/user/listall