From 812238060bf6ff0d9b953ecf90bb2a38417ac54d Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Mon, 18 May 2026 14:24:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20docker-compose=20UID/GID=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=80=BC=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20docker.sh=20logs=20=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 9 +++++---- docker-compose.yml | 14 ++++++++------ scripts/docker.sh | 9 ++++++++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3f75a8f..e899b40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # AstrAI Dockerfile - Multi-stage Build (Optimized) # Build stage - use base image with minimal build tools -FROM nvidia/cuda:12.6.0-base-ubuntu24.04 AS builder +FROM ubuntu:24.04 AS builder WORKDIR /app @@ -18,7 +18,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins RUN python3.12 -m venv --copies /opt/venv ENV PATH="/opt/venv/bin:$PATH" -# Copy source code and install dependencies +# Copy source code and install (deps read from pyproject.toml) COPY astrai/ ./astrai/ COPY pyproject.toml . RUN pip install --no-cache-dir --upgrade pip \ @@ -26,13 +26,14 @@ RUN pip install --no-cache-dir --upgrade pip \ --extra-index-url https://download.pytorch.org/whl/cu126 # Production stage -FROM nvidia/cuda:12.6.0-base-ubuntu24.04 AS production +FROM ubuntu:24.04 AS production WORKDIR /app -# Install Python 3.12 runtime +# Install Python 3.12 runtime and healthcheck dependency RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ python3.12 \ + curl \ && rm -rf /var/lib/apt/lists/* # Copy virtual environment from builder diff --git a/docker-compose.yml b/docker-compose.yml index 225bc5b..71cf702 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,13 @@ services: server: - build: . - image: astrai:latest + build: + context: . + dockerfile: Dockerfile + user: "${UID:-1000}:${GID:-1000}" ports: - "8000:8000" volumes: - ./params:/app/params:ro - - ./checkpoints:/app/checkpoints command: python -m scripts.tools.server --port 8000 --device cuda deploy: resources: @@ -25,13 +26,14 @@ services: server-cpu: profiles: [cpu] - build: . - image: astrai:latest + build: + context: . + dockerfile: Dockerfile + user: "${UID:-1000}:${GID:-1000}" ports: - "8000:8000" volumes: - ./params:/app/params:ro - - ./checkpoints:/app/checkpoints command: python -m scripts.tools.server --port 8000 --device cpu healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8000/health"] diff --git a/scripts/docker.sh b/scripts/docker.sh index 83648f7..30b7a8c 100755 --- a/scripts/docker.sh +++ b/scripts/docker.sh @@ -16,6 +16,7 @@ NC='\033[0m' # No Color IMAGE_NAME="astrai" IMAGE_TAG="latest" REGISTRY="" +CONTAINER_ID="" # Print colored messages print_info() { @@ -175,6 +176,10 @@ main() { PORT="$2" shift 2 ;; + --container) + CONTAINER_ID="$2" + shift 2 + ;; --gpu) GPU=true shift @@ -197,6 +202,7 @@ main() { echo " --dockerfile FILE Dockerfile path (default: Dockerfile)" echo " --context PATH Build context (default: .)" echo " --port PORT Port for run (default: 8000)" + echo " --container ID Container ID for logs" echo " --gpu Enable GPU support" echo " --help Show this help message" echo "" @@ -205,6 +211,7 @@ main() { echo " $0 build --tag v1.0.0" echo " $0 run --port 8080" echo " $0 run --gpu" + echo " $0 logs --container abc123" echo " $0 push --registry ghcr.io/username" exit 0 ;; @@ -237,7 +244,7 @@ main() { show_info ;; logs) - show_logs "$2" + show_logs "$CONTAINER_ID" ;; "") print_error "No command specified. Use --help for usage"