> For the complete documentation index, see [llms.txt](https://docs.readyidc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.readyidc.com/gpu-as-a-service/linux/docker/using-gpu-with-container.md).

# How to using vGPU 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.readyidc.com/gpu-as-a-service/linux/docker/using-gpu-with-container.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
