Dockerfile 파일 내용

2025. 5. 2. 19:33quadruped

gpu에 docker image가 필요하여 만든 dockerfile 파일 입니다.

 

---------------------------------------------------------------------------------------------

 

# Ubuntu 22.04 기반 딥러닝/컴퓨터 비전 Docker 이미지
# 이 Dockerfile은 YOLO12 및 DeepLab 기반 컴퓨터 비전 작업을 위한 환경을 구성합니다.

# 기본 이미지: NVIDIA CUDA 12.2 및 Ubuntu 22.04 기반
FROM nvidia/cuda:12.2.0-cudnn8-devel-ubuntu22.04

# 메타데이터 설정
LABEL maintainer="우대현 (pulisul@hanmir.com)"
LABEL description="딥러닝 및 컴퓨터 비전 환경 (YOLO12, DeepLabV3+, PyTorch, TensorFlow)"
LABEL version="1.0"

# 환경 변수 설정
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PATH="/root/.local/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"

# 기본 시스템 패키지 설치
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    cmake \
    git \
    curl \
    wget \
    ca-certificates \
    software-properties-common \
    libssl-dev \
    libffi-dev \
    pkg-config \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    openssh-server \
    tmux \
    rsync \
    htop \
    iftop \
    g++ \
    vim \
    nano \
    less \
    locales \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# 로케일 설정
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8 \
    LANGUAGE=en_US:en \
    LC_ALL=en_US.UTF-8

# Python 3.10 설치
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3.10 \
    python3.10-dev \
    python3.10-distutils \
    python3-pip \
    python3-setuptools \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && ln -sf /usr/bin/python3.10 /usr/bin/python3 \
    && ln -sf /usr/bin/python3 /usr/bin/python \
    && pip3 install --upgrade pip

# 필요한 Python 패키지 설치
# 1. 기본 패키지
RUN pip install --no-cache-dir \
    numpy==1.24.3 \
    pandas==2.0.3 \
    scipy==1.11.3 \
    scikit-learn==1.3.0 \
    scikit-image==0.21.0 \
    matplotlib==3.7.2 \
    seaborn==0.12.2 \
    pillow==10.0.0 \
    tqdm

# 2. 딥러닝 프레임워크
RUN pip install --no-cache-dir \
    torch==2.1.0 \
    torchvision \
    torchaudio \
    tensorflow==2.14.0 \
    keras==2.14.0 \
    onnx==1.14.1 \
    pytorch-lightning==2.0.9

# 3. 컴퓨터 비전 라이브러리
RUN pip install --no-cache-dir \
    opencv-python==4.8.0.* \
    opencv-contrib-python==4.8.0.* \
    albumentations==1.3.1 \
    mmdet==3.1.0 \
    openmim

# 4. YOLO12 (Ultralytics)
RUN pip install --no-cache-dir \
    ultralytics

# 5. 성능 최적화 도구
RUN pip install --no-cache-dir \
    flashattention==2.0.8 \
    nvidia-dali-cuda120==1.25.0 \
    deepspeed==0.10.0 \
    accelerate

# NVIDIA Apex 설치 (성능 최적화용)
RUN git clone https://github.com/NVIDIA/apex \
    && cd apex \
    && pip install -v --disable-pip-version-check --no-cache-dir --no-build-isolation --config-settings "--build-option=--cpp_ext" --config-settings "--build-option=--cuda_ext" ./ \
    && cd .. \
    && rm -rf apex

# 6. 개발 및 실험 환경
RUN pip install --no-cache-dir \
    jupyterlab==3.6.3 \
    ipywidgets \
    wandb \
    mlflow==2.7.1 \
    dvc==3.15.0

# 7. 데이터셋 관리 및 모델 서빙 도구
RUN pip install --no-cache-dir \
    pycocotools \
    datasets==2.14.5 \
    fastapi==0.103.1 \
    uvicorn \
    streamlit==1.27.2

# TensorFlow Serving 설치
RUN echo "deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | tee /etc/apt/sources.list.d/tensorflow-serving.list \
    && curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | apt-key add - \
    && apt-get update && apt-get install -y --no-install-recommends \
    tensorflow-model-server \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# TorchServe 설치
RUN pip install --no-cache-dir torchserve==0.8.2 torch-model-archiver torch-workflow-archiver

# VS Code Server 설치
RUN curl -fsSL https://code-server.dev/install.sh | sh

# DeepLabV3+ (TensorFlow Hub 모델 사용)
RUN pip install --no-cache-dir \
    tensorflow-hub

# 작업 디렉토리 설정
WORKDIR /workspace

# 환경 변수 설정을 위한 Shell 설정
RUN echo 'export PATH=$PATH:/usr/local/cuda/bin' >> ~/.bashrc \
    && echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64' >> ~/.bashrc

# SSH 서버 설정
RUN mkdir -p /var/run/sshd \
    && echo 'root:password' | chpasswd \
    && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
    && sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config

# 포트 노출 (SSH, Jupyter, TensorFlow Serving, FastAPI 등)
EXPOSE 22 8888 8501 8080 8000

# 시작 스크립트 생성
RUN echo '#!/bin/bash\n\
service ssh start\n\
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root &\n\
code-server --bind-addr 0.0.0.0:8080 --auth none &\n\
tail -f /dev/null' > /start.sh \
    && chmod +x /start.sh

# 컨테이너 시작 시 실행할 명령 설정
CMD ["/start.sh"]