Dockerfile
FROM openjdk:11.0.16-jre
ADD bp.jar bp.jar
EXPOSE 9090
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=cq", "-Duser.timezone=Asia/Shanghai", "bp.jar"]
重启脚本
#!/bin/bash
AppName=bp.jar
SourceLogPath=logs
TargetLogPath=`pwd`/logs
SourcePort=8080
TargetPort=9090
ImageName=bp:v1
ContainerName=bp
echo "Start build ${AppName} to docker image ${ImageName}"
docker build -t ${ImageName} . > /dev/null
docker ps -q --filter "name=${ContainerName}" | grep -q .
dockerStatus=`echo $?`
if [ ${dockerStatus} = '0' ];
then
echo "Stop container ${ContainerName}";
docker stop ${ContainerName}
fi
docker ps -aq --filter "name=${ContainerName}" | grep -q .
dockerStatus=`echo $?`
if [ ${dockerStatus} = '0' ];
then
echo "Remove container ${ContainerName}";
docker rm -f ${ContainerName}
fi
echo "Run image ${ImageName} with container name ${ContainerName}, expose port ${SourcePort} to ${TargetPort}, log will save at ${TargetLogPath}"
docker run -d --name ${ContainerName} -e TZ=Asia/Shanghai -v ${TargetLogPath}:/${SourceLogPath} -p ${TargetPort}:${SourcePort} -it ${ImageName}
标签:ContainerName,Java,jar,echo,ImageName,bp,docker,包打
From: https://www.cnblogs.com/seliote/p/16824738.html