#!bin/bash
mysqlNetwork="mysql-net"
redisNetwork="redis-net"
haloRootPath=/data/halo
# 判断用户是否输入版本号
version=$1
if [ ! "$version"] ;then
version=latest
echo "Your halo version is blank.It will be upgrade by latest"
else
echo "Your halo version is $version.It will be upgrade by $version"
fi
# 停止并删除容器和镜像
docker rm -f halo
docker image rm halohub/halo
echo 'Halo container & image all deleted'
echo 'Now to pull latest image & start container'
# 拉取最新版/指定版本镜像
pullProcess=$(docker pull halohub/halo:$version)
echo $pullProcess
# 启动docker容器
start=$(docker run -it -d --name halo --net halo-net --link mysql:mysql --link redis:redis -p 8090:8090 -v $haloRootPath:/root/.halo -e "JAVA_OPTS='-Xmx512m'" --restart=unless-stopped halohub/halo:$version)
for line in $start
do
echo $line
done
# 设置容器网络互联
docker network connect $mysqlNetwork halo
docker network connect $redisNetwork halo
# 配置容器互联后重启Halo
docker restart halo
echo "Halo '$version' upgrade successed"