启动脚本:删除镜像->新建镜像->启动容器
CONTAINER="open-api"
IMAGE_NAME="open-api"
echo "service image: $IMAGE_NAME"
echo "service container: $CONTAINER"
cid=$(docker ps|grep "$CONTAINER"|awk '{print $1}')
if [ -n "$cid" ];
then
echo "docker stop $cid"
docker stop $cid && docker rm $cid
fi
# 获取最新的镜像
imgid=$(docker images|grep "$IMAGE_NAME"| grep ':latest'|awk '{print $3}')
if [ -n "$imgid" ];
then
echo "docker rmi $imgid"
docker rmi "$imgid"
fi
# 新建镜像
docker build -t open-api .
# 创建并启动容器
docker run -d --restart=always --name open-api -p 8080:8080 -v /etc/localtime:/etc/localtime \
-v /home/service/open-api:/home/service/open-api open-api