-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·75 lines (67 loc) · 2.15 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# 容器名称和端口配置
containers=("kimi-free-api" "glm-free-api" "qwen-free-api" "step-free-api" "metaso-free-api" "spark-free-api" "emohaa-free-api")
# 在这里修改端口
ports=(8000 8001 8002 8003 8004 8005 8006)
# 停止并删除容器
for i in "${!containers[@]}"; do
container=${containers[$i]}
echo "Processing $container..."
if docker ps -a | grep -q $container; then
echo "Stopping $container..."
docker stop $container
echo "Removing $container..."
docker rm $container
else
echo "$container does not exist, skipping stop and remove."
fi
# 删除镜像
image="vinlic/${container}"
if docker images | grep -q $image; then
echo "Removing image $image..."
docker rmi $image
else
echo "Image $image does not exist, skipping remove."
fi
done
# 如果指定了 -del 参数,那么脚本到此结束
if [ "$1" == "-del" ]; then
echo "Deleted successfully"
exit 0
fi
# 网络诊断
echo "Checking network connection to Docker Hub..."
if ! curl -s https://registry-1.docker.io/v2/ > /dev/null; then
echo "Cannot connect to Docker Hub. Please check your network connection."
exit 1
fi
# 拉取最新的镜像,并确保每个操作之间的顺序
for container in "${containers[@]}"; do
echo ""
echo "Pulling image for $container..."
echo ""
success=false
for attempt in {1..3}; do
if docker pull vinlic/${container}:latest; then
echo "Successfully pulled $container image."
success=true
break
else
echo "Attempt $attempt failed, retrying..."
sleep 5
fi
done
if [ "$success" = false ]; then
echo "Failed to pull $container image after several attempts. Stopping script."
exit 1
fi
done
# 运行新的容器
echo "Starting new containers..."
for i in "${!containers[@]}"; do
container=${containers[$i]}
port=${ports[$i]}
echo ""
echo "Starting container $((i+1)): $container on port $port"
docker run -it -d --init --name $container -p $port:8000 -e TZ=Asia/Shanghai vinlic/${container}:latest
done