1、制作Maven镜像
(1)使用ubuntu镜像
docker run -it --name build_maven ubuntu
(2)下载并安装java
wget --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn/java/jdk/8u212-b10/59066701cf1a433da9770636fbc4c9aa/jdk-
8u212-linux-x64.tar.gz
tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/local/
cd /usr/local
mv jdk-8u131-linux-x64 jdk
sudo ln -s /usr/local/jdk/bin/java /bin/java
java -version
(3)安装maven
apt-get update
apt-get install maven
(4)保存并后台运行镜像
docker commit build_maven maven
docker run -d --name maven maven bash -c "while true;do sleep 1d;done"
2、编写Dockerfile
FROM openjdk:8-jre-alpine
COPY ./test.jar /home/test.jar
RUN echo "Asia/Shanghai" > /etc/timezone
WORKDIR /home
ENTRYPOINT ["java", "-jar", "test.jar"]
3、编写Jenkins构建脚本
API_NAME="test"
API_VERSION="1.0.0"
API_PORT=9999
IMAGE_NAME="test"
CON_NAME=$API_NAME-$API_VERSION
#关闭已经存在的容器和镜像
cid=$(docker ps -a| grep "$CON_NAME" | awk '{print }')
if [ "$cid" != "" ]; then
docker rm -f $cid
fi
imgid=$(docker images| grep "$IMAGE_NAME" | awk '{print }')
if [ "$imgid" != "" ]; then
docker rmi -f $imgid
fi
#使用maven构建jar包
docker cp . maven:/home/$API_NAME/
docker exec maven mvn -f /home/$API_NAME/pom.xml clean
docker exec maven mvn -f /home/$API_NAME/pom.xml install
docker cp maven:/home/$API_NAME/target/nacos-ir.qa.proxy.jar .
#构建容器
docker build --rm -t $IMAGE_NAME .
#运行容器
docker run -d -p $API_PORT:8080 -v /etc/localtime:/etc/localtime:ro \
-v $PATH/config:/home/config --name $CON_NAME $IMAGE_NAME \
--spring.config.location=/home/config/application.properties
参考资料
https://www.csdn.net/tags/NtjaQg2sMDA1OTEtYmxvZwO0O0OO0O0O.html
alpine运行程序提示not found_指剑的博客-CSDN博客
docker alpine制作jdk、瘦身版jre 镜像,镜像上传到阿里云_qq_43059674的博客-CSDN博客_alpine jdk
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)