# Using GPU with container

#### Installing Docker

```
curl -sSL https://get.docker.com | sh
```

#### Installing Toolkit

ทดสอบว่า vm สามารถใช้งาน docker ได้หรือไม่

```
docker run --gpus all --rm nvcr.io/nvidia/cuda:13.0.0-base-ubuntu24.04 nvidia-smi
```

หากไม่สามารถใช้งานได้ ให้ทำการติดตั้ง Cuda Toolkit และ nvidia-container-toolkit

```
# ติดตั้ง cuda toolkit ให้ตรงกับ version ของ cuda
apt isntall -y cuda-toolkit-$CUDA_TOOLKIT

# ติดตั้ง nvidia-container-toolkit
apt install -y nvidia-container-toolkit
```

#### Example

ตัวอย่างการใช้งาน vGPU โดยที่แต่ละ container ใช้งาน profile ของ vGPU ต่างกัน

* ตรวจสอบ Profile GPU

```
nvidia-smi -L
GPU 0: NVIDIA RTX PRO 6000 Blackwell Server Edition (UUID: GPU-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  MIG 1g.24gb     Device  0: (UUID: MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  MIG 1g.24gb     Device  1: (UUID: MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  MIG 1g.24gb     Device  2: (UUID: MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  MIG 1g.24gb     Device  3: (UUID: MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
```

ตัวอย่างไฟล์ docker-compose.yml

* ในตัวอย่างจะเป็นการ load test performance ของ vgpu ในแต่ละ container

```
services:
  app-1:
    image: gpu_burn
    container_name: mig-app-1
    command: "./gpu_burn 3600"
    restart: unless-stopped
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ["MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
              capabilities: [gpu]

  app-2:
    image: gpu_burn
    container_name: mig-app-2
    command: "./gpu_burn 3600"
    restart: unless-stopped
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ["MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
              capabilities: [gpu]

  app-3:
    image: gpu_burn
    container_name: mig-app-3
    command: "./gpu_burn 3600"
    restart: unless-stopped
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ["MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
              capabilities: [gpu]

  app-4:
    image: gpu_burn
    container_name: mig-app-4
    command: "./gpu_burn 3600"
    restart: unless-stopped
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ["MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
              capabilities: [gpu]
              
    app-5:
    image: gpu_burn
    container_name: mig-app-5
    command: "./gpu_burn 3600"
    restart: unless-stopped
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ["MIG-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
              capabilities: [gpu]
```

จะเห็นได้ว่า แต่ละ container จะมีการเรียกใช้งาน device\_id ของ profile ที่ต่างกัน แต่จะมี container 4 กับ 5 ที่มีการใช้งาน vgpu อันเดียวกัน

<figure><img src="/files/FwCGvsi32I2hlxwOtG1A" alt=""><figcaption></figcaption></figure>

* รันไฟล์ docker-compose.ym

```
docker compose up -d

# ตรวจสอบ container
docker ps
```

<figure><img src="/files/V5KHtNRNhQ4JOZRfWbUo" alt=""><figcaption></figcaption></figure>

* ตรวจสอบว่าการ์ดมีการเรียกใช้งาน vGPU

```
nvidia-smi
หรือ
nvitop
```

<figure><img src="/files/LjUw7vE2DESUeX3yM0z8" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/FwCGvsi32I2hlxwOtG1A" alt=""><figcaption></figcaption></figure>

* หากต้องการตรวจสอบแต่ละ container สามารถทำได้แบบเข้าใช้งาน docker ปกติ

```
docker exec -it <container_name> sh
```

<figure><img src="/files/4AACQSOOOpYlS8tR3VPv" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://readyidc.gitbook.io/readyidc-docs/gpu-as-a-service/using-gpu-with-container.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
