Skip to content

Commit 4381dfc

Browse files
authored
Update Dockerfile
1 parent de59eaf commit 4381dfc

File tree

1 file changed

+42
-48
lines changed

1 file changed

+42
-48
lines changed

Dockerfile

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,55 @@
1-
# Base image with CUDA 12.6 and Ubuntu 24.04
2-
FROM nvidia/cuda:12.6.0-devel-ubuntu24.04
3-
4-
# Set environment variables
5-
ENV DEBIAN_FRONTEND=noninteractive
6-
ENV PYTHONUNBUFFERED=1
7-
ENV PYTHONDONTWRITEBYTECODE=1
8-
# Fix for Ubuntu 24.04 PEP 668 (allows global pip install)
9-
ENV PIP_BREAK_SYSTEM_PACKAGES=1
10-
ENV TORCH_CUDA_ARCH_LIST="8.0;8.6;8.9;9.0"
11-
12-
# Set the working directory
13-
WORKDIR /workspace
14-
15-
# 1. Install System Dependencies
16-
# CHANGED: 'libgl1-mesa-glx' -> 'libgl1' (Fixes exit code 100)
1+
# 1. PLATFORM PINNING: Essential for CUDA wheels.
2+
# PyTorch with CUDA does not have wheels for ARM64 (Apple Silicon).
3+
# We force linux/amd64 so Docker pulls the compatible x86 binary.
4+
FROM --platform=linux/amd64 python:3.11-slim
5+
6+
# 2. ENVIRONMENT VARIABLES
7+
# Keeps Python from buffering stdout/stderr (logs appear immediately)
8+
# and prevents python from writing .pyc files.
9+
ENV PYTHONDONTWRITEBYTECODE=1 \
10+
PYTHONUNBUFFERED=1 \
11+
PIP_NO_CACHE_DIR=1
12+
13+
WORKDIR /app
14+
15+
# 3. SYSTEM DEPENDENCIES
16+
# Install basic build tools and libraries often required by vision/audio packages
1717
RUN apt-get update && apt-get install -y --no-install-recommends \
18+
build-essential \
1819
git \
19-
wget \
20-
curl \
21-
vim \
22-
ffmpeg \
2320
libgl1 \
2421
libglib2.0-0 \
25-
python3-pip \
26-
python3-dev \
27-
python3-venv \
28-
&& apt-get clean && rm -rf /var/lib/apt/lists/*
29-
30-
# 2. Setup Python 3.12 as default
31-
RUN ln -s /usr/bin/python3 /usr/bin/python
32-
33-
# 3. Install PyTorch 2.7.0 with PINNED dependencies
34-
# Pinning versions ensures compatibility with PyTorch 2.7
35-
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
36-
pip install --no-cache-dir \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
# 4. INSTALL PYTORCH (Heavy Layer)
25+
# We do this BEFORE copying requirements.txt or app code.
26+
# This ensures Docker caches this heavy layer (2GB+) and doesn't re-download
27+
# it unless you specifically change the Torch version.
28+
RUN pip install --upgrade pip setuptools wheel && \
29+
pip install \
3730
torch==2.7.0 \
3831
torchvision==0.22.0 \
3932
torchaudio==2.7.0 \
4033
--index-url https://download.pytorch.org/whl/cu126
4134

42-
# 4. Clone and Install SAM3
43-
RUN git clone https://github.com/facebookresearch/sam3.git && \
44-
cd sam3 && \
45-
pip install -e . && \
46-
pip install -e ".[notebooks,dev,train]"
35+
# 5. INSTALL OTHER REQUIREMENTS
36+
COPY requirements.txt .
37+
RUN pip install -r requirements.txt
4738

48-
# 5. Install JupyterLab
49-
RUN pip install jupyterlab
39+
# 6. SECURITY: CREATE NON-ROOT USER
40+
# Running as root is a security risk. Create a user 'appuser'.
41+
RUN addgroup --system --gid 1001 appgroup && \
42+
adduser --system --uid 1001 --gid 1001 appuser
5043

51-
# 6. Setup Entrypoint for Hugging Face Login
52-
RUN echo '#!/bin/bash\n\
53-
echo "----------------------------------------------------------------"\n\
54-
echo "SAM3 Environment Ready."\n\
55-
echo "Run: huggingface-cli login"\n\
56-
echo "----------------------------------------------------------------"\n\
57-
exec "$@"' > /usr/local/bin/entrypoint.sh && chmod +x /usr/local/bin/entrypoint.sh
44+
# 7. COPY APP CODE
45+
COPY . .
5846

59-
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
47+
# Change ownership of the app directory to the non-root user
48+
RUN chown -R appuser:appgroup /app
6049

61-
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--allow-root", "--no-browser"]
50+
# Switch to non-root user
51+
USER appuser
52+
53+
# 8. ENTRYPOINT
54+
# Update 'main.py' to your actual entry script
55+
CMD ["python", "main.py"]

0 commit comments

Comments
 (0)