Docker Model Runner 간편 가이드: 명령어 및 예제

Docker Model Runner 명령어의 빠른 참조

Docker 모델 러너 (DMR)는 2025년 4월에 도입된 Docker의 공식 솔루션으로, 로컬에서 AI 모델을 실행하는 데 사용됩니다. 이 체크리스트는 모든 필수 명령어, 설정 및 최고의 실천 방법에 대한 빠른 참조를 제공합니다.

docker 모델 러너에서 사용 가능한 gemma 모델 목록

설치

Docker Desktop

GUI를 통해 Docker 모델 러너를 활성화하십시오:

  1. Docker Desktop을 열고
  2. 설정AI 탭으로 이동
  3. Docker 모델 러너 활성화를 클릭
  4. Docker Desktop을 재시작

/home/rg/prj/hugo-pers/content/post/2025/10/docker-model-runner-cheatsheet/docker-model-runner_w678.jpg docker 모델 러너 윈도우

Docker 엔진 (Linux)

플러그인 패키지를 설치하십시오:

# Ubuntu/Debian
sudo apt-get update
sudo apt-get install docker-model-plugin

# Fedora/RHEL
sudo dnf install docker-model-plugin

# Arch Linux
sudo pacman -S docker-model-plugin

설치를 확인하십시오:

docker model --help

핵심 명령어

모델 끌어오기

Docker Hub에서 사전 패키징된 모델을 끌어오십시오:

# 기본 끌어오기
docker model pull ai/llama2

# 특정 버전 끌어오기
docker model pull ai/llama2:7b-q4

# 사용자 정의 레지스트리에서 끌어오기
docker model pull myregistry.com/models/mistral:latest

# 네임스페이스에서 사용 가능한 모델 목록 보기
docker search ai/

모델 실행

자동 API 제공과 함께 모델을 시작하십시오:

# 기본 실행 (상호작용)
docker model run ai/llama2 "What is Docker?"

# 서비스로 실행 (백그라운드)
docker model run -d --name my-llm ai/llama2

# 사용자 정의 포트로 실행
docker model run -p 8080:8080 ai/llama2

# GPU 사양으로 실행
docker model run --gpus 0,1 ai/llama2

# 메모리 제한으로 실행
docker model run --memory 8g ai/llama2

# 환경 변수로 실행
docker model run -e MODEL_CONTEXT=4096 ai/llama2

# 지속 가능한 데이터를 위한 볼륨 마운트로 실행
docker model run -v model-data:/data ai/llama2

모델 목록 보기

다운로드된 모델과 실행 중인 모델을 확인하십시오:

# 모든 다운로드된 모델 목록 보기
docker model ls

# 실행 중인 모델 목록 보기
docker model ps

# 상세 정보와 함께 목록 보기
docker model ls --all --format json

# 이름으로 필터링
docker model ls --filter "name=llama"

모델 중지

실행 중인 모델 인스턴스를 중지하십시오:

# 특정 모델 중지
docker model stop my-llm

# 모든 실행 중인 모델 중지
docker model stop $(docker model ps -q)

# 타임아웃과 함께 중지
docker model stop --time 30 my-llm

모델 삭제

로컬 스토리지에서 모델을 삭제하십시오:

# 특정 모델 삭제
docker model rm ai/llama2

# 강제로 삭제 (실행 중인 경우에도)
docker model rm -f ai/llama2

# 사용되지 않은 모델 삭제
docker model prune

# 모든 모델 삭제
docker model rm $(docker model ls -q)

사용자 정의 모델 패키징

GGUF에서 OCI 아티팩트 생성

자신의 GGUF 모델을 패키징하십시오:

# 기본 패키징
docker model package --gguf /path/to/model.gguf myorg/mymodel:latest

# 메타데이터와 함께 패키징
docker model package \
  --gguf /path/to/model.gguf \
  --label "description=Custom Llama model" \
  --label "version=1.0" \
  myorg/mymodel:v1.0

# 패키징 및 한 번에 푸시
docker model package --gguf /path/to/model.gguf --push myorg/mymodel:latest

# 사용자 정의 컨텍스트 크기로 패키징
docker model package \
  --gguf /path/to/model.gguf \
  --context 8192 \
  myorg/mymodel:latest

모델 출판

레지스트리에 모델을 푸시하십시오:

# Docker Hub에 로그인
docker login

# Docker Hub에 푸시
docker model push myorg/mymodel:latest

# 프라이빗 레지스트리에 푸시
docker login myregistry.com
docker model push myregistry.com/models/mymodel:latest

# 태그 및 푸시
docker model tag mymodel:latest myorg/mymodel:v1.0
docker model push myorg/mymodel:v1.0

API 사용

OpenAI 호환 엔드포인트

Docker 모델 러너는 자동으로 OpenAI 호환 API를 노출합니다:

# API와 함께 모델 시작
docker model run -d -p 8080:8080 --name llm ai/llama2

# 채팅 완성
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama2",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

# 텍스트 생성
curl http://localhost:8080/v1/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama2",
    "prompt": "Once upon a time",
    "max_tokens": 100
  }'

# 스트리밍 응답
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama2",
    "messages": [{"role": "user", "content": "Tell me a story"}],
    "stream": true
  }'

# 사용 가능한 모델 목록 API로 보기
curl http://localhost:8080/v1/models

# 모델 정보
curl http://localhost:8080/v1/models/llama2

Docker Compose 구성

기본 Compose 파일

version: '3.8'

services:
  llm:
    image: docker-model-runner
    model: ai/llama2:7b-q4
    ports:
      - "8080:8080"
    environment:
      - MODEL_CONTEXT=4096
      - MODEL_TEMPERATURE=0.7
    volumes:
      - model-data:/root/.cache
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

volumes:
  model-data:

다중 모델 설정

version: '3.8'

services:
  llama:
    image: docker-model-runner
    model: ai/llama2
    ports:
      - "8080:8080"
    
  mistral:
    image: docker-model-runner
    model: ai/mistral
    ports:
      - "8081:8080"
    
  embedding:
    image: docker-model-runner
    model: ai/nomic-embed-text
    ports:
      - "8082:8080"

더 고급 Docker Compose 구성 및 명령어는 우리의 Docker Compose 체크리스트를 참조하십시오. 이 문서는 네트워킹, 볼륨 및 오케스트레이션 패턴을 다룹니다.

환경 변수

모델 행동을 환경 변수로 구성하십시오:

# 컨텍스트 창 크기
MODEL_CONTEXT=4096

# 온도 (0.0-1.0)
MODEL_TEMPERATURE=0.7

# Top-p 샘플링
MODEL_TOP_P=0.9

# Top-k 샘플링
MODEL_TOP_K=40

# 최대 토큰
MODEL_MAX_TOKENS=2048

# GPU 레이어 수
MODEL_GPU_LAYERS=35

# 배치 크기
MODEL_BATCH_SIZE=512

# 스레드 수 (CPU)
MODEL_THREADS=8

# 자세한 로깅 활성화
MODEL_VERBOSE=true

# 인증을 위한 API 키
MODEL_API_KEY=your-secret-key

환경 변수와 함께 실행하십시오:

docker model run \
  -e MODEL_CONTEXT=8192 \
  -e MODEL_TEMPERATURE=0.8 \
  -e MODEL_API_KEY=secret123 \
  ai/llama2

GPU 구성

자동 GPU 감지

DMR은 자동으로 사용 가능한 GPU를 감지하고 사용합니다:

# 모든 GPU 사용
docker model run --gpus all ai/llama2

# 특정 GPU 사용
docker model run --gpus 0 ai/llama2

# 여러 특정 GPU 사용
docker model run --gpus 0,1,2 ai/llama2

# 메모리 제한과 함께 GPU 사용
docker model run --gpus all --memory 16g ai/llama2

CPU 전용 모드

GPU가 사용 가능할 때 CPU 추론을 강제로 실행하십시오:

docker model run --no-gpu ai/llama2

다중 GPU 텐서 병렬성

대규모 모델을 여러 GPU에 분산하십시오:

docker model run \
  --gpus all \
  --tensor-parallel 2 \
  ai/llama2-70b

점검 및 디버깅

모델 세부 정보 보기

# 모델 구성 보기
docker model inspect ai/llama2

# 모델 레이어 보기
docker model history ai/llama2

# 모델 크기 및 메타데이터 확인
docker model inspect --format='{{.Size}}' ai/llama2

로그 및 모니터링

# 모델 로그 보기
docker model logs llm

# 실시간으로 로그 보기
docker model logs -f llm

# 마지막 100줄 보기
docker model logs --tail 100 llm

# 타임스탬프와 함께 로그 보기
docker model logs -t llm

성능 통계

# 리소스 사용량
docker model stats

# 특정 모델 통계
docker model stats llm

# JSON 형식으로 통계 보기
docker model stats --format json

네트워킹

API 노출

# 기본 포트 (8080)
docker model run -p 8080:8080 ai/llama2

# 사용자 정의 포트
docker model run -p 3000:8080 ai/llama2

# 특정 인터페이스에 바인딩
docker model run -p 127.0.0.1:8080:8080 ai/llama2

# 여러 포트
docker model run -p 8080:8080 -p 9090:9090 ai/llama2

네트워크 구성

# 사용자 정의 네트워크 생성
docker network create llm-network

# 사용자 정의 네트워크에서 모델 실행
docker model run --network llm-network --name llm ai/llama2

# 기존 네트워크에 연결
docker model run --network host ai/llama2

보안

접근 제어

# API 키 인증으로 실행
docker model run \
  -e MODEL_API_KEY=my-secret-key \
  ai/llama2

# 인증과 함께 사용
curl http://localhost:8080/v1/chat/completions \
  -H "Authorization: Bearer my-secret-key" \
  -H "Content-Type: application/json" \
  -d '{"model": "llama2", "messages": [...]}'

레지스트리 인증

# 프라이빗 레지스트리에 로그인
docker login myregistry.com -u username -p password

# 프라이빗 레지스트리에서 끌어오기
docker model pull myregistry.com/private/model:latest

# 자격 증명 도우미 사용
docker login --password-stdin < token.txt

최고의 실천 방법

모델 선택

# 더 빠른 추론을 위해 양자화된 모델 사용
docker model pull ai/llama2:7b-q4     # 4비트 양자화
docker model pull ai/llama2:7b-q5     # 5비트 양자화
docker model pull ai/llama2:7b-q8     # 8비트 양자화

# 모델 변형 확인
docker search ai/llama2

리소스 관리

# 메모리 제한 설정
docker model run --memory 8g --memory-swap 16g ai/llama2

# CPU 제한 설정
docker model run --cpus 4 ai/llama2

# GPU 메모리 제한
docker model run --gpus all --gpu-memory 8g ai/llama2

건강 상태 확인

# 건강 상태 확인으로 실행
docker model run \
  --health-cmd "curl -f http://localhost:8080/health || exit 1" \
  --health-interval 30s \
  --health-timeout 10s \
  --health-retries 3 \
  ai/llama2

프로덕션 오케스트레이션

프로덕션 배포에 Kubernetes를 사용하는 경우, Docker 모델 러너 컨테이너는 표준 Kubernetes 매니페스트를 사용하여 오케스트레이션할 수 있습니다. 리소스 제한, 자동 확장 및 로드 밸런싱을 위한 배포를 정의하십시오. 포괄적인 Kubernetes 명령어 참조 및 배포 패턴은 우리의 Kubernetes 체크리스트를 참조하십시오.

# 예시: Kubernetes 클러스터에 배포
kubectl apply -f llm-deployment.yaml

# 배포 확장
kubectl scale deployment llm --replicas=3

# 서비스로 노출
kubectl expose deployment llm --type=LoadBalancer --port=8080

문제 해결

일반적인 문제

모델이 시작되지 않음:

# 사용 가능한 디스크 공간 확인
df -h

# 상세한 오류 로그 확인
docker model logs --tail 50 llm

# GPU 가용성 확인
nvidia-smi  # NVIDIA GPU 사용 시

메모리 부족 오류:

# 더 작은 양자화된 모델 사용
docker model pull ai/llama2:7b-q4

# 컨텍스트 크기 축소
docker model run -e MODEL_CONTEXT=2048 ai/llama2

# 배치 크기 제한
docker model run -e MODEL_BATCH_SIZE=256 ai/llama2

추론 속도 느림:

# GPU 사용량 확인
docker model stats llm

# GPU가 사용되고 있는지 확인
docker model logs llm | grep -i gpu

# GPU 레이어 수 증가
docker model run -e MODEL_GPU_LAYERS=40 ai/llama2

진단 명령어

# 시스템 정보
docker model system info

# 디스크 사용량
docker model system df

# 사용되지 않은 리소스 정리
docker model system prune

# 전체 정리 (모든 모델 삭제)
docker model system prune -a

통합 예시

Python 통합

import openai

# Docker 모델 러너를 위한 클라이언트 구성
client = openai.OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="not-needed"  # DMR은 기본적으로 키가 필요하지 않음
)

# 채팅 완성
response = client.chat.completions.create(
    model="llama2",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.choices[0].message.content)

# 스트리밍
stream = client.chat.completions.create(
    model="llama2",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Bash 스크립트

#!/bin/bash

# 실행 중이지 않으면 모델 시작
if ! docker model ps | grep -q "llm"; then
    docker model run -d --name llm -p 8080:8080 ai/llama2
    echo "모델이 시작되기를 기다리고 있습니다..."
    sleep 10
fi

# API 호출
curl -s http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama2",
    "messages": [{"role": "user", "content": "'"$1"'"}]
  }' | jq -r '.choices[0].message.content'

Node.js 통합

import OpenAI from 'openai';

const client = new OpenAI({
    baseURL: 'http://localhost:8080/v1',
    apiKey: 'not-needed'
});

async function chat(message) {
    const completion = await client.chat.completions.create({
        model: 'llama2',
        messages: [{ role: 'user', content: message }]
    });
    
    return completion.choices[0].message.content;
}

// 사용법
const response = await chat('Docker 모델 러너란 무엇인가요?');
console.log(response);

유용한 링크

공식 문서

관련 체크리스트

비교 기사