一、war打包镜像(survey,analytics,trac系统)
- 代码打包成war
- 准备tomcat的server.xml文件,修改connector中8080端口为项目的端口
修改前:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
修改后(问卷系统):
<Connector port="28280" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
- 编写Dockerfile文件
FROM tomcat
MAINTAINER chow
ENV REFRESHED_AT 2021-07-18
ADD server.xml /usr/local/tomcat/conf
ADD survey-app-1.0.0-SNAPSHOT.war /usr/local/tomcat/webapps/survey.war
EXPOSE 28280
ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]
- 生成docker镜像
docker build -t cem/survey:latest --rm .
- 运行docker 镜像
docker run -id --name=survey -p 28280:28280 87afb1e9d040
87afb1e9d040为镜像hash
二、jar打包镜像(sso,job,rbac,davinci系统)
- 代码打包成jar包
- 编写Dockerfile文件
FROM java:8
MAINTAINER chow
ADD ./target/davinci-app-1.0.0-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar","--spring.profiles.active=test"]
- 生成docker镜像
docker build -t cem/davinci:latest --rm .
三、阿里服务器交互
$ docker login --username=webe****@gmail.com registry.cn-hangzhou.aliyuncs.com
$ docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/****/imagename:[镜像版本号]
$ docker push registry.cn-hangzhou.aliyuncs.com/****/imagename:[镜像版本号]
$ docker pull registry.cn-hangzhou.aliyuncs.com/****/imagename:[镜像版本号]
四、docker镜像运行
#后台运行
Docker run –id –name=rbac –p 28580:28580 rbac
docker run -id --name=davinci --env DAVINCI3_HOME=/bash/bin -p 8080:8080 1652578551c6
#进入镜像
Docker exec –it rbac /bin/bash