Setup EC2 for Docker with GPU
Follow these steps to render videos on EC2 in a Docker container.
These steps are opinionated, but specify a reference that works.
Setup EC2 for Docker with GPU
1
Follow the instructions for GPUs on EC2. You can skip installing Chrome, Node.js and cloning the repo to render a video.2
Install NVIDIA Container toolkit:Add keyringbash
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpgcurl -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.listsudo apt-get update
Add keyringbash
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpgcurl -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.listsudo apt-get update
Install toolkitbash
sudo apt-get install -y nvidia-container-toolkit
Install toolkitbash
sudo apt-get install -y nvidia-container-toolkit
3
Install Docker: Add Docker's official GPG keybash
sudo apt-get updatesudo apt-get install ca-certificates curl gnupgsudo install -m 0755 -d /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgsudo chmod a+r /etc/apt/keyrings/docker.gpg
Add Docker's official GPG keybash
sudo apt-get updatesudo apt-get install ca-certificates curl gnupgsudo install -m 0755 -d /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgsudo chmod a+r /etc/apt/keyrings/docker.gpg
Add keyringbash
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/nullsudo apt-get update
Add keyringbash
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/nullsudo apt-get update
Install Dockerbash
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Install Dockerbash
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
4
Configure Docker to use the NVIDIA runtime Configure the NVIDIA container runtimebash
sudo nvidia-ctk runtime configure --runtime=dockersudo systemctl restart docker
Configure the NVIDIA container runtimebash
sudo nvidia-ctk runtime configure --runtime=dockersudo systemctl restart docker
5
Create two files, Dockerfile
and entrypoint.sh
. You can for example create them using the nano ./file-to-create
command. Use CtrlX to save and quit. Dockerfilebash
FROM node:20-bookwormRUN apt-get updateRUN apt-get install -y curl gnupg git chromiumRUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpgRUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" > /etc/apt/sources.list.d/nodesource.listRUN apt-get cleanRUN rm -rf /var/lib/apt/lists/*# Clone the repoRUN git clone https://github.com/remotion-dev/gpu-scene.gitWORKDIR /gpu-sceneRUN npm install# Copy the entrypoint script into the imageCOPY entrypoint.sh .CMD ["sh", "./entrypoint.sh"]
Dockerfilebash
FROM node:20-bookwormRUN apt-get updateRUN apt-get install -y curl gnupg git chromiumRUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpgRUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" > /etc/apt/sources.list.d/nodesource.listRUN apt-get cleanRUN rm -rf /var/lib/apt/lists/*# Clone the repoRUN git clone https://github.com/remotion-dev/gpu-scene.gitWORKDIR /gpu-sceneRUN npm install# Copy the entrypoint script into the imageCOPY entrypoint.sh .CMD ["sh", "./entrypoint.sh"]
entrypoint.shbash
#!/bin/bashnpx remotion render --gl=angle-egl Scene out/video.mp4
entrypoint.shbash
#!/bin/bashnpx remotion render --gl=angle-egl Scene out/video.mp4
6
Build the container and run a sample render: bash
sudo docker build . -t remotion-docker-gpusudo docker run --gpus all --runtime=nvidia -e "NVIDIA_DRIVER_CAPABILITIES=all" remotion-docker-gpu
bash
sudo docker build . -t remotion-docker-gpusudo docker run --gpus all --runtime=nvidia -e "NVIDIA_DRIVER_CAPABILITIES=all" remotion-docker-gpu