自己随手写的脚本,如观看者想要取用请进行修改
脚本代码在下方,如需观看请关注
- jar包与脚本在同一级目录
[root@localhost app]# pwd
/root/app
[root@localhost app]# ls
discovery-1.0.0.RELEASE.jar update.sh
- 执行脚本
[root@localhost app]# ./update.sh
+-------------------------------------+
| 服务发布脚本 |
+-------------------------------------+
Sending build context to Docker daemon 39.9 MB
Step 1/4 : FROM java:8
---> d23bdf5b1b1b
Step 2/4 : ADD ./discovery-1.0.0.RELEASE.jar /data/discovery-1.0.0.RELEASE.jar
---> f18294092888
Removing intermediate container 0cb6159cb0d1
Step 3/4 : WORKDIR /data/
---> 3f473c8e5b8d
Removing intermediate container be3a72e6ed9c
Step 4/4 : CMD sh -c java -jar discovery-1.0.0.RELEASE.jar
---> Running in 801bcf06774c
---> d74cfbe3bdd8
Removing intermediate container 801bcf06774c
Successfully built d74cfbe3bdd8
7ebf9744f8e66d05353d46f477ab3334a06cd3c8c5aa902cb60744e62611f759
- 查看容器运行状态
[root@localhost app]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ebf9744f8e6 discovery:latest "sh -c 'java -jar ..." 35 seconds ago Up 35 seconds 0.0.0.0:8761->8761/tcp discovery
- 访问测试
– 代码
#!/bin/bash
echo "+-------------------------------------+"
echo "| 服务发布脚本 |"
echo "+-------------------------------------+"
jar=`ls | grep jar$`
name=`ls | grep jar$ | awk -F '-1' '{print $1}'`
image=$name':latest'
dockerfile () {
cat > dockerfile <<EOF FROM java:8 ADD ./$jar /data/$jar WORKDIR /data/ CMD ["sh","-c","java -jar $jar"] EOF
}
images () {
docker build -t $image .
}
fabu () {
docker run -itd --name $name $image
}
clearfile () {
rm -rf /app/dockerfile
}
dockerfile
images
if [ $name == discovery ]
then
docker run -itd -p 8761:8761 --name $name $image
fi
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/101843.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...