Reputation: 21
I am trying desperately to setup a Docker image based on nvidia/cudagl image and add ROS2 humble distro on it. The reason is theat I need this ENV for future Gazebo simulations with the NVIDIA GPU Capabilities.
The problem is that the official nvidia/cudagl image is based on ubuntu 20.04 and ROS2 Humble requires ubuntu 22.04 so I can't build the image properly
anyone knows **how can I make a docker image that is based on cudagl-ubuntu 20.04 and modify it to be a layer on top of ubuntu 22.04 ** so I will get something like this in my image layers
i basically followed this article its just that's iit a bit outdated text
If you have other suggestions or can guide me to source code of simillar dockerfile it would be great tnxxxx :))
I tried using this offcial Nvidia docker file and as my base image
FROM nvidia/cudagl:11.4.2-base-ubuntu20.04
and adding ROS2 humble in source installation on ubuntu 22.04 (my machine)
but it doesnt work also tried building cudagl image from bae of ubutu 22.04 image just to serve as base for further adding a layer of ros2 - but this also cann't be built
# Use Ubuntu 22.04 as the base image
FROM ubuntu:22.04 as base
FROM base as base-amd64
ENV NVARCH x86_64
ENV NVIDIA_REQUIRE_CUDA "cuda>=11.4 brand=tesla,driver>=418,driver<419 brand=tesla,driver>=450,driver<451"
ENV NV_CUDA_CUDART_VERSION 11.4.108-1
ENV NV_CUDA_COMPAT_PACKAGE cuda-compat-11-4
FROM base as base-arm64
ENV NVARCH sbsa
ENV NVIDIA_REQUIRE_CUDA "cuda>=11.4"
ENV NV_CUDA_CUDART_VERSION 11.4.108-1
FROM base-${TARGETARCH}
ARG TARGETARCH
LABEL maintainer "NVIDIA CORPORATION <[email protected]>"
RUN apt-get update && apt-get install -y --no-install-recommends \
gnupg2 curl ca-certificates && \
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/${NVARCH}/3bf863cc.pub | apt-key add - && \
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/${NVARCH} /" > /etc/apt/sources.list.d/cuda.list && \
apt-get purge --autoremove -y curl \
&& rm -rf /var/lib/apt/lists/*
ENV CUDA_VERSION 11.4.2
# For libraries in the cuda-compat-* package: https://docs.nvidia.com/cuda/eula/index.html#attachment-a
RUN apt-get update && apt-get install -y --no-install-recommends \
cuda-cudart-11-4=${NV_CUDA_CUDART_VERSION} \
${NV_CUDA_COMPAT_PACKAGE} \
&& rm -rf /var/lib/apt/lists/*
# Required for nvidia-docker v1
RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf \
&& echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf
ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH}
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
# Install OpenGL packages
RUN dpkg --add-architecture i386 \
&& apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
libglvnd-dev libglvnd-dev:i386 \
libgl1-mesa-dev libgl1-mesa-dev:i386 \
libegl1-mesa-dev libegl1-mesa-dev:i386 \
libgles2-mesa-dev libgles2-mesa-dev:i386 \
&& rm -rf /var/lib/apt/lists/*
COPY NGC-DL-CONTAINER-LICENSE /
# nvidia-container-runtime
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
Upvotes: 2
Views: 4573
Reputation: 95
I have run into the same issue. The following solution is working under the WSL2 system with Ubuntu22.04 running Docker Desktop 4.19.0 (106363). I have not tested on real Ubuntu but I should have fewer problems than I encountered in finding this solution.
From this issue answer on Github that redirects to this official MS guide here, the following base Dockefile that I slightly modified to add the latest Cuda capabilities is capable of rendering OpenGL apps:
FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04 as runtime
ARG DEBIAN_FRONTEND=noninteractive
# Uncomment the lines below to use a 3rd party repository
# to get the latest (unstable from mesa/main) mesa library version
RUN apt-get update && apt install -y software-properties-common
RUN add-apt-repository ppa:oibaf/graphics-drivers -y
RUN apt update && apt install -y \
vainfo \
mesa-va-drivers \
mesa-utils
ENV LIBVA_DRIVER_NAME=d3d12
ENV LD_LIBRARY_PATH=/usr/lib/wsl/lib
CMD vainfo --display drm --device /dev/dri/card0
Then, you can install ROS2 from apt.
Regarding additional env vars:
NVIDIA_VISIBLE_DEVICES
should be already set to all and NVIDIA_DRIVER_CAPABILITIES
to compute,utility
.
You may want to set:
ENV NVIDIA_DRIVER_CAPABILITIES \
${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics,video
or
ENV NVIDIA_DRIVER_CAPABILITIES all
Then with the following, you control the device for the hw acceleration: Nvidia card (similarly for AMD):
ENV MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
or integrated Intel (if supported):
ENV MESA_D3D12_DEFAULT_ADAPTER_NAME=Intel
or software, which actually for me gives faster FPS probably due to WSL2 (my system) not being optimized:
ENV LIBGL_ALWAYS_SOFTWARE=1
Upvotes: 1