Project

General

Profile

NVidia GPU 연동 » History » Version 3

상혁 손, 2025-10-11 21:31

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