1.制作镜像流程
2. 部署案例
2.1 导入数据库
-
创建数据库和账号密码
mysql> create database if not exists java_demo default charset utf8 ; # 创建数据库,默认utf8 Query OK, 1 row affected (0.00 sec) mysql> GRANT all on java_demo.* to 'java_demo'@'%' IDENTIFIED BY 'Aa@9953013'; #创建用户并授权 Query OK, 0 rows affected, 1 warning (0.02 sec) mysql> flush privileges; #刷新 Query OK, 0 rows affected (0.00 sec)
-
导入数据
[root@localhost ~]# mysql -h127.0.0.1 -ujava_demo -p'Aa@9953013' < db/tables_ly_tomcat.sql mysql: [Warning] Using a password on the command line interface can be insecure.
-
修改连接数据库文件:src/main/resources/application.yml
server: port: 8080 spring: datasource: url: jdbc:mysql://192.168.0.230:3306/java_demo?characterEncoding=utf-8 username: java_demo password: Aa@9953013 driver-class-name: com.mysql.jdbc.Driver freemarker: allow-request-override: false cache: true check-template-location: true charset: UTF-8 content-type: text/html; charset=utf-8 expose-request-attributes: false expose-session-attributes: false expose-spring-macro-helpers: false suffix: .ftl template-loader-path: - classpath:/templates/
2.2 创建jenkins项目
2.2 进行项目编写
- 点击配置
-
复制github源代码地址
-
这里是github地址,可以使用没有密码拉取
-
java打包:mvn clean package -Dmaven.test.skip=true
-
编写dockerfile制作镜像
cd $WORKSPACE && mv target/*.war target/ROOT.war cat > Dockerfile <<EOF FROM tomcat MAINTAINER shichao@scajy.cn COPY target/ROOT.war /usr/local/tomcat/webapps/ROOT.war EOF docker build -t harbor.scajy.org/scajy/java:${tag} . docker login -uadmin -p'12345678' harbor.scajy.org docker push harbor.scajy.org/scajy/java:${tag}