Skip to main content

为 Docker 配置带 GPU 的 EC2

note

该指南已过时,将不再适用。
截至目前,裸GPU指南 是最新的。

请密切遵循以下步骤,在 Docker 容器中于 EC2 上渲染视频。
这些步骤带有个人观点,但指定了一个可行的参考。

🌐 Follow these steps closely to render videos on EC2 in a Docker container.
These steps are opinionated, but specify a reference that works.

警告:偏离指示,例如:

🌐 A word of warning: Deviating from the instructions, like:

  • 选择不同的 AMI
  • 选择不同的 Docker 基础
  • 选择除了 EC2 之外的其他东西
  • 选择不同的主机

可能导致 GPU 无法工作。在这种情况下,很难进行调试。 我们建议首先按照这些说明操作,并在拥有可正常工作的设置后再进行更改。

🌐 may lead to the GPU not working. In this case, it is hard to debug.
We recommend to first follow these instructions and make changes once you have a working setup.

为 Docker 配置带 GPU 的 EC2

🌐 Setup EC2 for Docker with GPU

请按照 EC2上的GPU的说明操作。你可以跳过安装Chrome、Node.js和克隆仓库来渲染视频。

安装 NVIDIA 容器工具包:

Add keyring
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list sudo apt-get update
Install toolkit
sudo apt-get install -y nvidia-container-toolkit

安装 Docker:

Add Docker's official GPG key
sudo apt-get update sudo apt-get install ca-certificates curl gnupg sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg
Add keyring
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
Install Docker
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

配置 Docker 使用 NVIDIA 运行时

Configure the NVIDIA container runtime
sudo nvidia-ctk runtime configure --runtime=docker sudo systemctl restart docker

创建两个文件,Dockerfileentrypoint.sh。例如,你可以使用 nano ./file-to-create 命令创建它们。使用 Ctrl X 保存并退出。

Dockerfile
FROM node:20-bookworm RUN apt-get update RUN apt-get install -y curl gnupg git RUN rm -rf /var/lib/apt/lists/* # Clone the repo RUN git clone https://github.com/remotion-dev/gpu-scene.git WORKDIR /gpu-scene RUN npm install # Copy the entrypoint script into the image COPY entrypoint.sh . CMD ["sh", "./entrypoint.sh"]
entrypoint.sh
#!/bin/bash npx remotion render --gl=angle-egl Scene out/video.mp4

构建容器并运行示例渲染:

sudo docker build . -t remotion-docker-gpu
sudo docker run --gpus all --runtime=nvidia -e "NVIDIA_DRIVER_CAPABILITIES=all" remotion-docker-gpu

调试

🌐 Debugging

使用 npx remotion gpu 命令获取 chrome://gpu 的输出以验证 GPU 是否正常工作。

🌐 Use the npx remotion gpu command to get the output of chrome://gpu to verify that the GPU is working.

另请参阅

🌐 See also