I have been trying to build a docker container in Ubuntu-22.04 using the following Dockerfile (modified from https://github.com/sunsided/ros-gazebo-gpu-docker.git)
FROM nvidia/cudagl:11.4.2-base-ubuntu20.04
ENV TZ=Asia/Kolkata \
DEBIAN_FRONTEND=noninteractive
# Run a full upgrade and install utilities for development.
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
mesa-utils \
vim \
nano \
build-essential gdb \
cmake cmake-curses-gui \
git \
ssh \
curl \
&& rm -rf /var/lib/apt/lists/*
# Register the ROS package sources.
ENV UBUNTU_RELEASE=focal
RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $UBUNTU_RELEASE main" > /etc/apt/sources.list.d/ros-latest.list'
RUN wget --output-document - \
https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
# Install ROS.
RUN apt-get update && apt-get install -y \
ros-noetic-desktop-full \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential\
&& rm -rf /var/lib/apt/lists/*
# Initialize rosdep
RUN rosdep init
# Only for nvidia-docker 1.0
LABEL com.nvidia.volumes.needed="nvidia_driver"
# ENV PATH /usr/local/nvidia/bin:${PATH}
# ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH}
# nvidia-container-runtime (nvidia-docker2)
ENV NVIDIA_VISIBLE_DEVICES \
${NVIDIA_VISIBLE_DEVICES:-all}
ENV NVIDIA_DRIVER_CAPABILITIES \
${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics
# Some QT-Apps/Gazebo don't show controls without this
ENV QT_X11_NO_MITSHM 1
# Create users and groups.
ARG ROS_USER_ID=1000
ARG ROS_GROUP_ID=1000
RUN addgroup --gid $ROS_GROUP_ID ros \
&& useradd --gid $ROS_GROUP_ID --uid $ROS_USER_ID -ms /bin/bash -p "$(openssl passwd -1 ros)" -G root,sudo ros \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Source the ROS configuration.
RUN echo "source /opt/ros/noetic/setup.bash" >> /home/ros/.bashrc
USER ros
RUN rosdep update
WORKDIR /home/${USER}
The Dockerfile is inside a docker folder in the home directory and is run using
docker build ~/Docker -t ros_noetic
Then the following noetic_image.bash file is used to run the docker container from the home directory
#!/usr/bin/env bash
# See http://wiki.ros.org/docker/Tutorials/Hardware%20Acceleration
set -euo pipefail
# See README.md for building this image.
CONTAINER_NAME=ros
DOCKER_IMAGE=ros_noetic
# Which GPUs to use; see https://github.com/NVIDIA/nvidia-docker
GPUS="all"
XSOCK=/tmp/.X11-unix
XAUTH=`pwd`/.tmp/docker.xauth
XAUTH_DOCKER=/tmp/.docker.xauth
if [ ! -f $XAUTH ]
then
xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/')
if [ ! -z "$xauth_list" ]
then
echo "$xauth_list" | xauth -f $XAUTH nmerge -
else
touch $XAUTH
fi
chmod a+r $XAUTH
fi
docker run --rm -it \
--name "$CONTAINER_NAME" \
--gpus "$GPUS" \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--env="XAUTHORITY=$XAUTH_DOCKER" \
--volume="$XSOCK:$XSOCK:rw" \
--volume="$XAUTH:$XAUTH_DOCKER:rw" \
$DOCKER_IMAGE \
bash
On running the bash file the following error pops up
$ ./noetic_image.bash
xauth: error in locking authority file /home/<user>/.tmp/docker.xauth
Where are we supposed to find the .tmp folder? Although this can be run without including the xauth, on running gazebo libgl error pops up.
Could anyone help me with modifying the Dockerfile or bash file or suggest any other better method. I would like to use docker to run ros noetic with gpu and opengl support for gazebo projects. Note that I have already installed the official NVIDIA Container Toolkit from https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
$ docker run -it --rm --gpus all ubuntu nvidia-smi
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
bccd10f490ab: Pull complete
Digest: sha256:77906da86b60585ce12215807090eb327e7386c8fafb5402369e421f44eff17e
Status: Downloaded newer image for ubuntu:latest
Tue Mar 12 14:44:29 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.14 Driver Version: 550.54.14 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| 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 NVIDIA GeForce GTX 1650 Off | 00000000:01:00.0 Off | N/A |
| N/A 51C P0 15W / 50W | 5MiB / 4096MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+
Thank you for any help (well in advanced)!