services: diffsim-runner: build: . container_name: diffsim_runner # runtime: nvidia # 🔥 新增:端口映射 # 左边是宿主机端口,右边是容器端口 (Streamlit 默认 8501) ports: - "8601:8501" # 挂载目录:代码、数据、模型缓存 volumes: - .:/app # 当前目录代码映射到容器 /app - ./data:/app/data # 图片数据映射 - ./hf_cache:/root/.cache/huggingface # 模型缓存映射 environment: - NVIDIA_VISIBLE_DEVICES=all # 🔥 新增:设置国内 HF 镜像,确保每次启动容器都能由镜像站加速 - HF_ENDPOINT=https://hf-mirror.com deploy: resources: reservations: devices: - driver: nvidia count: 1 capabilities: [gpu] # 让容器启动后不退出,像一个虚拟机一样待命 # 你可以随时 docker exec 进去,然后手动运行 streamlit run app.py command: tail -f /dev/null restart: unless-stopped