mirror of
https://github.com/Wan-Video/Wan2.1.git
synced 2025-11-04 14:16:57 +00:00
This commit introduces comprehensive Docker support for running Wan2.1 video generation models locally with GPU acceleration. Changes: - Add Dockerfile with CUDA 12.1 support and optimized layer caching - Add docker-compose.yml for easy container orchestration - Add .dockerignore for efficient Docker builds - Add DOCKER_SETUP.md with detailed setup and troubleshooting guide - Add DOCKER_QUICKSTART.md for rapid deployment - Add docker-run.sh helper script for container management - Update Makefile with Docker management commands Features: - Full GPU support with NVIDIA Docker runtime - Single-GPU and multi-GPU (FSDP + xDiT) configurations - Memory optimization flags for consumer GPUs (8GB+) - Gradio web interface support on port 7860 - Volume mounts for models, outputs, and cache - Comprehensive troubleshooting and optimization guides - Production-ready security best practices The Docker setup supports all Wan2.1 models (T2V, I2V, FLF2V, VACE) and includes both 1.3B (consumer GPU) and 14B (high-end GPU) variants. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
184 lines
4.8 KiB
Bash
Executable File
184 lines
4.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Wan2.1 Docker Helper Script
|
|
# Quick start script for running Wan2.1 in Docker
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
BLUE='\033[0;34m'
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
CONTAINER_NAME="wan2.1-gpu"
|
|
IMAGE_NAME="wan2.1:latest"
|
|
MODELS_DIR="./models"
|
|
OUTPUTS_DIR="./outputs"
|
|
CACHE_DIR="./cache"
|
|
|
|
# Print header
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "${BLUE} Wan2.1 Docker Helper Script${NC}"
|
|
echo -e "${BLUE}========================================${NC}\n"
|
|
|
|
# Check if Docker is installed
|
|
if ! command -v docker &> /dev/null; then
|
|
echo -e "${RED}Error: Docker is not installed${NC}"
|
|
echo "Please install Docker first: https://docs.docker.com/engine/install/"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if Docker Compose is installed
|
|
if ! command -v docker compose &> /dev/null; then
|
|
echo -e "${RED}Error: Docker Compose is not installed${NC}"
|
|
echo "Please install Docker Compose: https://docs.docker.com/compose/install/"
|
|
exit 1
|
|
fi
|
|
|
|
# Function to check NVIDIA Docker runtime
|
|
check_nvidia_runtime() {
|
|
if ! docker run --rm --gpus all nvidia/cuda:12.1.1-base-ubuntu22.04 nvidia-smi &> /dev/null; then
|
|
echo -e "${YELLOW}Warning: NVIDIA Docker runtime not available${NC}"
|
|
echo "GPU acceleration will not be available"
|
|
echo "Install NVIDIA Container Toolkit: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html"
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
# Function to create directories
|
|
create_directories() {
|
|
echo -e "${BLUE}Creating required directories...${NC}"
|
|
mkdir -p "$MODELS_DIR" "$OUTPUTS_DIR" "$CACHE_DIR"
|
|
echo -e "${GREEN}✓ Directories created${NC}\n"
|
|
}
|
|
|
|
# Function to build Docker image
|
|
build_image() {
|
|
echo -e "${BLUE}Building Docker image...${NC}"
|
|
docker compose build
|
|
echo -e "${GREEN}✓ Docker image built successfully${NC}\n"
|
|
}
|
|
|
|
# Function to start container
|
|
start_container() {
|
|
echo -e "${BLUE}Starting Wan2.1 container...${NC}"
|
|
|
|
if check_nvidia_runtime; then
|
|
echo "Starting with GPU support..."
|
|
docker compose up -d wan2-1
|
|
else
|
|
echo "Starting in CPU-only mode..."
|
|
docker compose --profile cpu up -d wan2-1-cpu
|
|
CONTAINER_NAME="wan2.1-cpu"
|
|
fi
|
|
|
|
echo -e "${GREEN}✓ Container started successfully${NC}\n"
|
|
}
|
|
|
|
# Function to show status
|
|
show_status() {
|
|
echo -e "${BLUE}Container Status:${NC}"
|
|
docker compose ps
|
|
echo ""
|
|
}
|
|
|
|
# Function to show logs
|
|
show_logs() {
|
|
echo -e "${BLUE}Showing container logs (Ctrl+C to exit)...${NC}"
|
|
docker compose logs -f "$CONTAINER_NAME"
|
|
}
|
|
|
|
# Function to enter container
|
|
enter_container() {
|
|
echo -e "${BLUE}Entering container shell...${NC}"
|
|
docker compose exec wan2-1 bash || docker compose exec wan2-1-cpu bash
|
|
}
|
|
|
|
# Function to stop container
|
|
stop_container() {
|
|
echo -e "${BLUE}Stopping container...${NC}"
|
|
docker compose down
|
|
echo -e "${GREEN}✓ Container stopped${NC}\n"
|
|
}
|
|
|
|
# Function to show help
|
|
show_help() {
|
|
cat << EOF
|
|
Usage: ./docker-run.sh [COMMAND]
|
|
|
|
Commands:
|
|
build Build the Docker image
|
|
start Start the container
|
|
stop Stop the container
|
|
restart Restart the container
|
|
status Show container status
|
|
logs Show container logs
|
|
shell Enter container shell
|
|
clean Stop container and clean up
|
|
help Show this help message
|
|
|
|
Examples:
|
|
./docker-run.sh build # Build the image
|
|
./docker-run.sh start # Start the container
|
|
./docker-run.sh shell # Enter the container
|
|
./docker-run.sh logs # View logs
|
|
|
|
For detailed documentation, see DOCKER_SETUP.md
|
|
EOF
|
|
}
|
|
|
|
# Main script logic
|
|
case "${1:-start}" in
|
|
build)
|
|
create_directories
|
|
build_image
|
|
;;
|
|
start)
|
|
create_directories
|
|
if ! docker images | grep -q "$IMAGE_NAME"; then
|
|
build_image
|
|
fi
|
|
start_container
|
|
show_status
|
|
echo -e "${GREEN}Container is running!${NC}"
|
|
echo -e "Run ${BLUE}./docker-run.sh shell${NC} to enter the container"
|
|
echo -e "Run ${BLUE}./docker-run.sh logs${NC} to view logs"
|
|
;;
|
|
stop)
|
|
stop_container
|
|
;;
|
|
restart)
|
|
stop_container
|
|
start_container
|
|
;;
|
|
status)
|
|
show_status
|
|
;;
|
|
logs)
|
|
show_logs
|
|
;;
|
|
shell)
|
|
enter_container
|
|
;;
|
|
clean)
|
|
echo -e "${YELLOW}This will stop the container and remove volumes${NC}"
|
|
read -p "Are you sure? (y/N) " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
docker compose down -v
|
|
echo -e "${GREEN}✓ Cleanup complete${NC}"
|
|
fi
|
|
;;
|
|
help|--help|-h)
|
|
show_help
|
|
;;
|
|
*)
|
|
echo -e "${RED}Unknown command: $1${NC}"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|