容器内使用NVIDIA GPU加速Chrome
越来越多的应用是通过容器进行部署的,如何在容器内使用GPU在生产中非常有意义。本文介绍如果构建一个能够在容器内使用NVIDIA GPU加速Chrome的镜像
越来越多的应用是通过容器进行部署的,如何在容器内使用GPU在生产中非常有意义。本文介绍如果构建一个能够在容器内使用NVIDIA GPU加速Chrome的镜像。
GPU机型:g4dn.xlarge
显卡驱动:
nvidia-driver-branch-510-cuda
cuda-toolkit-11-6
镜像Dockerfile:
FROM nvidia/cuda:11.6.2-base-ubuntu20.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -y wget libgles2-mesa libegl1-mesa libnvidia-gl-510 && \
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt-get install -y ./google-chrome-stable_current_amd64.deb
构建容器:
docker build -t chrome-n-gpu .
运行容器:
docker run -it --gpus all chrome-n-gpu bash
在容器内查看显卡运行状态:
root@ba2ec58a77e4:/# nvidia-smi
Tue Sep 20 19:46:53 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.85.02 Driver Version: 510.85.02 CUDA Version: 11.6 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla T4 Off | 00000000:00:1E.0 Off | 0 |
| N/A 32C P0 24W / 70W | 0MiB / 15360MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
在容器内导出chrome://gpu信息:
/opt/google/chrome/chrome --no-sandbox --headless --use-gl=egl --print-to-pdf=out.pdf 'chrome://gpu'
注意:除了生成的PDF文件,这里执行过程输出的信息,对排查为什么没有GPU加速有重要作用
如果打开out.pdf文件能看到下面的信息,说明GPU加速是正常的:
最后修改于 2022-09-20
此篇文章的评论功能已经停用。