docker-打包发布脚本

思路:直接将jar包放到某个文件夹,通过脚本实现打包image,并发布

#目录下文件显示jar包、Dockerfile文件、打包启动脚本
[root@localhost mkpackge1]# ls
chinapopin-department-web-1.0-SNAPSHOT.jar  Dockerfile  qd.sh

#启动脚本内容
[root@localhost mkpackge1]# more qd.sh 
#!/bin/bash
dir=$(cd $(dirname $0);pwd)
i=${1-image_name}
#delete pod
docker rm -f $i
#delete image
docker rmi -f $i:latest
#makpage
cd $dir
docker build -t $i:latest .
#start pod
docker run --name $i --net=host -d $i:latest

#Dockerfile内容---注意需要修改jar的端口7002改成直接程序的
[root@localhost mkpackge1]# more Dockerfile 
FROM wukc/openjdk:8-jdk-alpine
COPY *.jar app.jar
EXPOSE 7002
ENTRYPOINT ["java","-jar","/app.jar"]

  

启动方式sh qd.sh deploy_name

[root@localhost mkpackge1]# sh qd.sh department-web
Error: No such container: department-web
Error: No such image: department-web:latest
Sending build context to Docker daemon  62.88MB
Step 1/4 : FROM wukc/openjdk:8-jdk-alpine
 ---> a3562aa0b991
Step 2/4 : COPY *.jar app.jar
 ---> 78df7f8f3236
Step 3/4 : EXPOSE 7002
 ---> Running in 282b3ebea0a9
Removing intermediate container 282b3ebea0a9
 ---> c7f08cf6df7c
Step 4/4 : ENTRYPOINT ["java","-jar","/app.jar"]
 ---> Running in 4f3fffde2313
Removing intermediate container 4f3fffde2313
 ---> ca0b0823f20f
Successfully built ca0b0823f20f
Successfully tagged department-web:latest
7121af112baf6fc8cd8376fcd0e56c337f76f1e29bd772b67dfa81ad54c9de67

#结果查看
[root@localhost mkpackge1]# docker images
REPOSITORY       TAG            IMAGE ID       CREATED         SIZE
department-web   latest         ca0b0823f20f   3 seconds ago   168MB
wukc/openjdk     8-jdk-alpine   a3562aa0b991   2 years ago     105MB

[root@localhost mkpackge1]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                  CREATED         STATUS         PORTS                    NAMES
7121af112baf   department-web:latest   "java -jar /app.jar"     6 seconds ago   Up 6 seconds                            department-web

  

  

posted @ 2021-11-03 11:32  苍茫宇宙  阅读(274)  评论(0编辑  收藏  举报