NVidia GPU 연동 » History » Version 2
상혁 손, 2025-10-11 21:29
| 1 | 1 | 상혁 손 | # Podman nVidia GPU 연동 |
|---|---|---|---|
| 2 | 2 | 상혁 손 | |
| 3 | 기준 podman version 5.6.2 |
||
| 4 | |||
| 5 | * podman test(정상 동작 확인용) |
||
| 6 | podman run --rm **--network=slirp4netns --security-opt=label=disable --device=nvidia.com/gpu=all** nvidia/cuda:12.2.3-base-ubuntu22.04 nvidia-smi |
||
| 7 | |||
| 8 | * 위 podman을 기반으로 동작하는 yml, Containerfile파일 만들기 |
||
| 9 | * docker-compose.yml |
||
| 10 | |||
| 11 | `version: '3.8'` |
||
| 12 | `services:` |
||
| 13 | `base-server:` |
||
| 14 | `build:` |
||
| 15 | `context: .` |
||
| 16 | `dockerfile: Containerfile` |
||
| 17 | `container_name: bigdata_server` |
||
| 18 | `restart: unless-stopped` |
||
| 19 | `network_mode: "host"` |
||
| 20 | |||
| 21 | `# podman-compose에서 동작하는 예시 방식` |
||
| 22 | `devices:` |
||
| 23 | `- "nvidia.com/gpu=all"` |
||
| 24 | |||
| 25 | `labels:` |
||
| 26 | `- "run.oci.runtime.podman.devices=all"` |
||
| 27 | |||
| 28 | `security_opt:` |
||
| 29 | `- label=disable # 또는 SELinux 사용시 제거하고 :Z 사용` |
||
| 30 | `- seccomp=unconfined` |
||
| 31 | |||
| 32 | `environment:` |
||
| 33 | `- NVIDIA_VISIBLE_DEVICES=all` |
||
| 34 | `- TZ=Asia/Seoul` |
||
| 35 | `- DB_HOST=localhost` |
||
| 36 | `- DB_PORT=15433` |
||
| 37 | `- DB_USER=spacs` |
||
| 38 | `- DB_PASSWORD=scaps` |
||
| 39 | `- DB_NAME=spacs` |
||
| 40 | |||
| 41 | `volumes:` |
||
| 42 | `- ./ssdoctors:/home/ssdoctors # (아래 node_modules 처리 참고)` |
||
| 43 | `- ./data/workspace:/workspace` |
||
| 44 | |||
| 45 | `# 2. PostgreSQL 서비스 (Bigdata용)` |
||
| 46 | `postgres:` |
||
| 47 | `build:` |
||
| 48 | `context: .` |
||
| 49 | `dockerfile: postgres.Containerfile` |
||
| 50 | `container_name: bigdata_postgresql # <<< 변경: 컨테이너 이름 변경` |
||
| 51 | `restart: unless-stopped` |
||
| 52 | `#pull_policy: always` |
||
| 53 | `#user: '70:70'` |
||
| 54 | `init: true` |
||
| 55 | `privileged: true` |
||
| 56 | `network_mode: "host"` |
||
| 57 | `ports:` |
||
| 58 | `- "15433:5432"` |
||
| 59 | `command: postgres -c port=15433 -c shared_preload_libraries=pg_cron -c cron.database_name=spacs` |
||
| 60 | `environment:` |
||
| 61 | `- TZ=Asia/Seoul` |
||
| 62 | `- POSTGRES_USER=spacs` |
||
| 63 | `- POSTGRES_PASSWORD=scaps` |
||
| 64 | `- POSTGRES_DB=spacs` |
||
| 65 | `- PGPORT=15433` |
||
| 66 | `volumes:` |
||
| 67 | `- ./data/postgresql:/var/lib/postgresql/data:Z` |
||
| 68 | `security_opt:` |
||
| 69 | `- label=disable` |
||
| 70 | `- seccomp=unconfined` |
||
| 71 | `#healthcheck:` |
||
| 72 | `# test: ["CMD-SHELL", "pg_isready -U spacs -d spacs -p 15433"]` |
||
| 73 | `# interval: 10s` |
||
| 74 | `# timeout: 5s` |
||
| 75 | `# retries: 5` |
||
| 76 | |||
| 77 | `volumes:` |
||
| 78 | `# (필요시 node_modules용 named volume 추가 – 아래 참고)` |
||
| 79 | |||
| 80 | * Containerfile |
||
| 81 | |||
| 82 | `# Containerfile` |
||
| 83 | |||
| 84 | `# 기반 이미지를 NVIDIA CUDA 이미지로 변경` |
||
| 85 | `FROM nvidia/cuda:12.2.2-devel-ubuntu22.04` |
||
| 86 | |||
| 87 | `#MAINTAINER "birdhead"` |
||
| 88 | |||
| 89 | `# 로케일 및 타임존 환경 변수 설정` |
||
| 90 | `ENV LANG en_US.UTF-8` |
||
| 91 | `ENV TZ=Asia/Seoul` |
||
| 92 | `ENV DEBIAN_FRONTEND=noninteractive` |
||
| 93 | |||
| 94 | `# 패키지 설치` |
||
| 95 | `RUN \` |
||
| 96 | `echo "deb http://kr.archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list && \` |
||
| 97 | `echo "deb http://kr.archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list && \` |
||
| 98 | `echo "deb http://kr.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list && \` |
||
| 99 | `echo "deb http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse" >> /etc/apt/sources.list && \` |
||
| 100 | `apt-get update && \` |
||
| 101 | `apt-get install -y --no-install-recommends \` |
||
| 102 | `cron rsyslog openssh-server supervisor \` |
||
| 103 | `build-essential vim curl wget git ca-certificates gnupg \` |
||
| 104 | `sudo pkg-config \` |
||
| 105 | `cmake g++ gdb \` |
||
| 106 | `libboost-all-dev libdcmtk-dev libsndfile1-dev \` |
||
| 107 | `libpq-dev libnsl-dev \` |
||
| 108 | `python3 python3-pip python3-venv \` |
||
| 109 | `ffmpeg libopenblas-dev && \` |
||
| 110 | `\` |
||
| 111 | `# --- SSH 호스트 키 생성 및 필요 디렉토리 설정 ---` |
||
| 112 | `ssh-keygen -A && \` |
||
| 113 | `mkdir -p /run/sshd && \` |
||
| 114 | `chown root:root /run/sshd && \` |
||
| 115 | `chmod 755 /run/sshd && \` |
||
| 116 | `\` |
||
| 117 | `# --- Node.js 22.x 버전 설치 시작 ---` |
||
| 118 | `curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \` |
||
| 119 | `apt-get install -y nodejs && \` |
||
| 120 | `# --- Node.js 설치 끝 ---` |
||
| 121 | `\` |
||
| 122 | `apt-get clean && \` |
||
| 123 | `rm -rf /var/lib/apt/lists/*` |
||
| 124 | |||
| 125 | `# 필요한 커스텀 파일들을 이미지에 미리 복사` |
||
| 126 | `COPY --chown=root:root ./system/etc/. /etc/` |
||
| 127 | `COPY --chown=root:root ./system/usr_local/. /usr/local/` |
||
| 128 | |||
| 129 | `# Set Timezone` |
||
| 130 | `RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone` |
||
| 131 | |||
| 132 | `# npm을 사용하여 pm2 전역 설치` |
||
| 133 | `RUN npm install pm2 -g && npm cache clean --force` |
||
| 134 | |||
| 135 | `# ssdoctors 사용자가 비밀번호 없이 sudo를 사용하도록 설정` |
||
| 136 | `RUN echo "ssdoctors ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ssdoctors` |
||
| 137 | |||
| 138 | `# supervisord.conf 파일을 컨테이너 안으로 복사` |
||
| 139 | `COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf` |
||
| 140 | |||
| 141 | `# 컨테이너 시작 시 실행할 명령` |
||
| 142 | `#CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]` |
||
| 143 | |||
| 144 | `# ✅ entrypoint.sh 스크립트 추가` |
||
| 145 | `COPY entrypoint.sh /entrypoint.sh` |
||
| 146 | `RUN chmod +x /entrypoint.sh` |
||
| 147 | |||
| 148 | `ENTRYPOINT ["/entrypoint.sh"]` |