Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This script is used to manage the open-webui Docker container.
- # It performs the following steps:
- #
- # Verifies the existence of the specified local directory for mounting to the container.
- # Verifies the existence of the specified container name and image name.
- # Retrieves the latest image from the Docker registry, if not already present or if an update is available.
- # If no container with the specified name is running, it launches a new container using the latest image.
- # If a container with the specified name is running and the image has been updated, it stops and removes the existing container, then launches a new container using the latest image.
- # ANSI escape codes for colored output
- RED='\033[0;31m'
- GREEN='\033[0;32m'
- YELLOW='\033[0;33m'
- NC='\033[0m' # No Color
- # Configuration Variables
- OBSIDIAN_FOLDER_PATH="/mnt/c/Users/MyWindowsUser/Documents/Obsidian Vault/"
- INTERNAL_SCAN_FOLDER_PATH="/app/backend/data/docs/obsidian-vault"
- CONTAINER_NAME="open-webui"
- IMAGE_NAME="ghcr.io/open-webui/open-webui:main"
- OPENAI_API_KEY="sk-YOUR-KEY-HERE"
- # Default open-webui docker run command
- # docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main
- # device type for whisper tts and embbeding models - "cpu" (default), "cuda" (nvidia gpu and CUDA required) or "mps" (apple silicon) - choosing this right can lead to better performance
- # We must pass this as an environment variable to the container
- RAG_EMBEDDING_MODEL_DEVICE_TYPE="cpu"
- # Check if docker is installed
- if ! [ -x "$(command -v docker)" ]; then
- echo -e "${RED}Error: docker is not installed.${NC}" >&2
- exit 1
- fi
- # Check if the local directory exists
- if [ ! -d "$OBSIDIAN_FOLDER_PATH" ]; then
- echo -e "${RED}Directory $OBSIDIAN_FOLDER_PATH does not exist.${NC}"
- exit 1
- fi
- # Check if Docker is installed and running
- if ! docker info >/dev/null 2>&1; then
- echo -e "${RED}Docker is not installed or not running.${NC}"
- exit 1
- fi
- # Check if the user has the necessary permissions to interact with Docker
- if ! docker ps >/dev/null 2>&1; then
- echo -e "${RED}You do not have the necessary permissions to interact with Docker.${NC}"
- exit 1
- fi
- echo -e "${YELLOW}Pulling the latest image...${NC}"
- docker pull $IMAGE_NAME
- # Get the ID of the latest image
- LATEST_IMAGE_ID=$(docker inspect --format="{{.Id}}" $IMAGE_NAME)
- # Check if a container with the specified name exists
- if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then
- # Get the ID of the image used by the existing container
- CONTAINER_IMAGE_ID=$(docker inspect --format="{{.Image}}" $CONTAINER_NAME)
- # If the existing container is not using the latest image, or if it's not currently running, stop and remove it
- if [ "$CONTAINER_IMAGE_ID" != "$LATEST_IMAGE_ID" ] || ! docker ps -q -f name=$CONTAINER_NAME >/dev/null 2>&1; then
- echo -e "${YELLOW}Stopping and removing existing container...${NC}"
- docker stop $CONTAINER_NAME
- docker rm $CONTAINER_NAME
- else
- # If the existing container is using the latest image and is currently running, there's nothing more to do
- echo -e "${GREEN}Container is up to date and running.${NC}"
- exit 0
- fi
- fi
- # Launch a new container
- echo -e "${YELLOW}Launching a new container...${NC}"
- docker run -d -p 3000:8080 --gpus all --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data -v "$OBSIDIAN_FOLDER_PATH":"$INTERNAL_SCAN_FOLDER_PATH" --name open-webui --restart always -e OPENAI_API_KEY="$OPENAI_API_KEY" -e RAG_EMBEDDING_MODEL_DEVICE_TYPE="$RAG_EMBEDDING_MODEL_DEVICE_TYPE" $IMAGE_NAME
- echo -e "${GREEN}Container launched successfully.${NC}"
Advertisement
Add Comment
Please, Sign In to add comment