利用docker-compose启动mysql+java项目

2019-07-28  本文已影响0人  白桦树97

>项目地址https://github.com/wangzhenle/JavaTest4

1. docker-compose.yaml:

version: '3'
services:
  web:
    build: ./docker/java
    container_name: web
    ports:
      - 18080:8080
    links:
      - mysql
    environment:
      MYSQL_HOST: mysql
      MYSQL_PORT: 3306
      MYSQL_USER: root
      MYSQL_PASS: 123456


  mysql:
    build: ./docker/mysql
    container_name: mysql
    #    ports:
    #      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: "123456"

2. Dockerfile:

FROM registry.saas.hand-china.com/tools/mysql:5.6

COPY sakila-schema.sql /mysql/sakila-schema.sql
COPY sakila-data.sql /mysql/sakila-data.sql

RUN cat /mysql/sakila-schema.sql > /docker-entrypoint-initdb.d/dump.sql
RUN cat /mysql/sakila-data.sql >> /docker-entrypoint-initdb.d/dump.sql

FROM registry.saas.hand-china.com/tools/javabase:0.5.0
COPY exam1-0.0.1-SNAPSHOT.jar /exam1-0.0.1-SNAPSHOT.jar
COPY start.sh /
CMD sh /start.sh

3. 构建和启动文件

#!/bin/bash
echo 开始编译项目
mvn clean package -Dmaven.test.skip=true
echo 编译编译完成
cp ./target/exam1-0.0.1-SNAPSHOT.jar ./docker/java/
echo 项目拷贝完成
docker-compose build
echo 镜像构建完成
#!/bin/bash
docker-compose up
echo 容器启动完成

4. 测试接口

#!/bin/bash
#登录接口
curl -X POST "http://localhost:18080/login/?name=MARY&password=SMITH"
echo

#分页查询film列表(PageHelper)
curl -X GET "http://localhost:18080/film/?page=2&pageSize=2"
echo

echo "增加一条customer数据"
R=$(curl -X POST -H "Content-type: application/json" -d '{"firstName":"小明","lastName":"xixi","email":"1","address":"47 MySakila Drive"}' "http://localhost:18080/customer/")

2,4s/^/#/g 将2到4行注释

echo "修改该条数据"
curl -X PUT -H "Content-type: application/json" -d '{"customerId":'${R}',"firstName":"小李","lastName":"xixi","email":"1","address":"47 MySakila Drive"}' "http://localhost:18080/customer/"


echo "删除该条数据"
curl -X DELETE "http://localhost:18080/customer/${R}"
上一篇下一篇

猜你喜欢

热点阅读