usse/react_usse/use_docker.sh

55 lines
1.2 KiB
Bash
Raw Normal View History

2023-12-27 22:04:07 +00:00
#!/bin/bash
CONTAINER_NAME="usse_react"
IMAGE_NAME="usse_react"
PORT_MAPPING="5000:3000"
COMMAND="bash"
ok () {
echo -e "[\033[32;1m+\033[0m] $@"
}
err () {
echo -e "[\033[31;1m!\033[0m] $@"
}
info () {
echo -e "[\033[34;1m-\033[0m] $@"
}
check_ret (){
if [ $? -ne 0 ]
then
err $1
exit -1
fi
}
if [[ "$1" == "remove" ]]; then
echo "Stopping the Docker container..."
docker stop ${CONTAINER_NAME} && docker rm ${CONTAINER_NAME}
exit 0
fi
if [[ "$1" == "rebuild" ]]; then
echo "Stopping and removing the Docker container..."
docker stop ${CONTAINER_NAME} && docker rm ${CONTAINER_NAME}
echo "Removing the Docker image..."
docker rmi ${IMAGE_NAME} || true
fi
# Check if the container image exists
if [[ ! "$(docker images -q ${IMAGE_NAME})" ]]; then
echo "Building the Docker container..."
docker build -t ${IMAGE_NAME} --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy .
check_ret "Docker build failed!"
fi
if [[ "$1" == "recreate" ]]; then
echo "Removing docker container for recreation..."
docker stop ${CONTAINER_NAME} && docker rm ${CONTAINER_NAME}
fi
# Run container
docker run --name ${CONTAINER_NAME} -p ${PORT_MAPPING} ${IMAGE_NAME}