1. 程式人生 > 其它 >docker-打包釋出指令碼

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

  

  

做一個決定,並不難,難的是付諸行動,並且堅持到底。