一、maven配置
下载地址
#maven环境配置(已经配置好jdk)
vim /etc/profile
export MAVEN_HOME=/mnt/maven/apache-maven-3.6.3
export PATH=${MAVEN_HOME}/bin:${PATH}
#使配置生效
source /etc/profile
#maven验证
root@t-master:# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /mnt/vos-vrpq55mx/maven/apache-maven-3.6.3
Java version: 1.8.0_261, vendor: Oracle Corporation, runtime: /mnt/vos-vrpq55mx/za/java/jdk1.8.0_261/jre
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-51-generic", arch: "amd64", family: "unix"
#修改setting文件
#指定jar包下载位置
<localRepository>/mnt/maven/apache-maven-3.6.3/space</localRepository>
#使用阿里云镜像
<mirror>
<!--This sends everything else to /public -->
<id>aliyun maven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
二、镜像打包
#springboot分别执行以下操作,生成jar包
mvn clean
mvn package
#在单独的文件夹下新建Dockerfile文件,内容如下
# jdk版本
FROM moxm/java:1.8-full
# 临时文件目录
VOLUME /tmp
# 把demo-0.0.1-SNAPSHOT.jar添加到容器里,并重命名为app.jar
ADD StudentScore-0.0.1-SNAPSHOT.jar appkht.jar
# 开放8080端口
EXPOSE 8088
# ENTRYPOINT 执行项目 app.jar。为了缩短 Tomcat 启动时间,添加一个系统属性指向 "/dev/urandom" 作为 Entropy Source.
ENTRYPOINT ["java","-jar","appkht.jar","-Xms512m","-Xmx1024m","-Djava.security.egd=file:/dev/./urandom"]
#执行打镜像命令
docker build -t appkht:1.0.0 .
#查看镜像
docker images
#docker运行测试
docker run -d --name demo-web1 -p 8080:8080 demo-web1:v1.0.0
# 传递变量,使用 -e 标记
docker run -d --name demo-web1 -p 8080:8080 -e "SPRING_PROFILES_ACTIVE=dev" demo-web1:v1.0.0
docker run -d --name appkht -p 30734:8088 appkht:1.0.0