docker 部署 JAVA项目脚本

echo 'build start!'
JENKINS_HOME=/var/jenkins_home/workspace/first-test
cd $JENKINS_HOME/target
cp $JENKINS_HOME/Dockerfile $JENKINS_HOME/target
service_name="firstdemo"
service_prot=18087
#查看镜像id
IID=$(docker images | grep "$service_name" | awk '{print $3}')
echo "IID $IID"
if [ -n "$IID" ]
then
echo "exist $SERVER_NAME image,IID=$IID"
#删除镜像
docker rmi -f $service_name
echo "delete $SERVER_NAME image"
#构建
docker build -t $service_name .
echo "build $SERVER_NAME image"
else
echo "no exist $SERVER_NAME image,build docker"
#构建
docker build -t $service_name .
echo "build $SERVER_NAME image"
fi
#查看容器id
CID=$(docker ps | grep "$SERVER_NAME" | awk '{print $1}')
echo "CID $CID"
if [ -n "$CID" ]
then
echo "exist $SERVER_NAME container,CID=$CID"
#停止
docker stop $service_name
#删除容器
docker rm $service_name
else
echo "no exist $SERVER_NAME container"
fi
#启动
docker run -d --name $service_name --net=host -p $service_prot:8080 $service_name
#查看启动日志
#docker logs -f $service_name

posted @ 2022-10-11 13:34  海逸庭  阅读(180)  评论(0编辑  收藏  举报