#!/bin/bash
read -p "请输入创建实例的个数:" LOOP
echo "创建实例个数:$LOOP"
read -p "请输入起始端口:" PORT
echo "起始端口:$PORT"
read -p "确认吗?(确认请输入y):" CONFIRM

if [ "$CONFIRM" == "y" ]; then
	echo "开始清理历史镜像和容器..."
	appid=$(docker ps | grep shell | awk '{print $1}')
	if [ -n "$appid" ]; then
		for id in $appid
		do
			docker stop $id
			docker rm $id
		done
	fi
	imageid=$(docker images | grep shell | awk '{print $3}')
	if [ -n "$imageid"]; then
		for id in $imageid
		do
			docker rmi $id
		done
	fi
	echo "开始构建镜像..."
	docker build -t shell .
	echo "开始创建容器..."
	for i in $( seq 0 $(($LOOP-1)))
	do
		echo $(($PORT+i))
		docker run -p $(($PORT+i)):8080 -d --name "shell_$(($PORT+i))" shell 
	done
	echo "完成"
else
	echo "退出实例创建"
	exit
fi

# To Be Continued!😎

Last Updated: 12/31/2020, 5:04:38 PM