<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tanishq Chaudhary on Medium]]></title>
        <description><![CDATA[Stories by Tanishq Chaudhary on Medium]]></description>
        <link>https://medium.com/@izzaaaatanishq?source=rss-6318e38c7f9c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j_5YO2BCYcPafCOBfEDlNg.png</url>
            <title>Stories by Tanishq Chaudhary on Medium</title>
            <link>https://medium.com/@izzaaaatanishq?source=rss-6318e38c7f9c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 01:21:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@izzaaaatanishq/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Running GUI Applications in Docker Containers with NVIDIA GPU Support: A Guide Using ROS]]></title>
            <link>https://izzaaaatanishq.medium.com/running-gui-applications-in-docker-containers-with-nvidia-gpu-support-a-guide-using-ros-46a04046c067?source=rss-6318e38c7f9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/46a04046c067</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[visualization]]></category>
            <dc:creator><![CDATA[Tanishq Chaudhary]]></dc:creator>
            <pubDate>Thu, 30 May 2024 07:03:28 GMT</pubDate>
            <atom:updated>2024-05-30T07:03:28.484Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Docker is a popular tool for containerizing applications, making it easier to develop, deploy, and manage software. While Docker works great for many applications, <em>running graphical user interface (GUI) applications inside Docker containers can be tricky. </em>This is <em>especially true when you need to use NVIDIA GPUs for tasks that require significant graphical processing power</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sKCEl7kfnutl24y9kU8L7w.png" /></figure><p>For developers using the Robot Operating System (ROS), this guide will show you how to run ROS GUI applications in Docker with NVIDIA GPU support. ROS is widely used in robotics for building and simulating robot software, and it often needs the power of GPUs for tasks like simulation and visualization.</p><p>In this guide, you will learn how to:</p><ul><li>Set up your environment to support Docker with NVIDIA GPUs.</li><li>Run your ROS GUI application inside a Docker container with GPU acceleration.</li></ul><p>By the end of this guide, you’ll be able to run your ROS applications in Docker with full GPU support, making your development process smoother and more efficient.</p><h3>Prerequisites</h3><p>In this section, we’ll cover the necessary steps and tools you’ll need to prepare before setting up and running your ROS GUI application in a Docker container with NVIDIA GPU support. This includes installing the required software and ensuring your system meets the necessary hardware requirements.</p><p><strong>System Requirements</strong></p><ul><li><strong>Operating System: </strong>Ubuntu 20.04 or greater</li></ul><p><strong>Required Software</strong></p><ol><li><strong>Docker Installation</strong></li></ol><ul><li>Install Docker by following the official Docker installation guide for Ubuntu: <a href="https://docs.docker.com/engine/install/ubuntu/"><strong><em>Install Docker on Ubuntu</em></strong></a></li><li>After installation, verify Docker is running correctly:</li></ul><pre>docker run hello-world</pre><p>2. <strong>NVIDIA Drivers</strong></p><ul><li>To verify the presence of NVIDIA drivers, execute the following command:</li></ul><pre>nvidia-smi</pre><ul><li>If NVIDIA drivers are not installed on your system, you can download and install them from the official website.</li></ul><p><strong>3. NVIDIA Container Toolkit</strong></p><p>To harness the power of NVIDIA GPUs within Docker containers, you’ll need to install the NVIDIA Container Toolkit on your Ubuntu system. Here’s how to do it:</p><ol><li>Installation Process:</li></ol><ul><li>Follow the official installation instructions provided by NVIDIA for Ubuntu from <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#install-guide"><strong><em>here</em></strong></a>.</li><li>Ensure you carefully follow each step to ensure a successful installation.</li></ul><p><strong><em>Suggested Steps for Installation:</em></strong></p><pre># Installing with Apt<br><br># 1. Configure the production repository:<br>curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \<br>  &amp;&amp; curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \<br>    sed &#39;s#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g&#39; | \<br>    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list<br><br># 2. Update the packages list from the repository:<br>sudo apt-get update<br><br># 3. Install the NVIDIA Container Toolkit packages:<br>sudo apt-get install -y nvidia-container-toolkit</pre><p>2. Configuration for Docker:</p><ul><li>After installing the NVIDIA Container Toolkit, it’s crucial to configure it to work seamlessly with Docker.</li><li>Refer to the configuration guide provided by NVIDIA to properly configure the toolkit for Docker integration.</li><li>This step is essential to ensure that Docker can access and utilize the NVIDIA GPU resources effectively.</li></ul><p><strong><em>Suggested Steps for Configuring with Docker:</em></strong></p><pre># Configuring Docker<br># 1. Configure the container runtime by using the nvidia-ctk command:<br>sudo nvidia-ctk runtime configure --runtime=docker<br><br># The nvidia-ctk command modifies the /etc/docker/daemon.json file on the host. The file is updated so that Docker can use the NVIDIA Container Runtime.<br><br># Restart the Docker daemon:<br><br>sudo systemctl restart docker</pre><p>By following these steps, you can install and configure the NVIDIA Container Toolkit on your Ubuntu system, enabling Docker to leverage the full potential of NVIDIA GPUs for your applications.</p><h3>Setting up the Environment</h3><p><strong>Grant Docker Access to X Server</strong></p><p>Allow Docker containers to access the X server by running the following command:</p><pre>xhost +local:docker</pre><p>This command grants permission for Docker containers running on the local machine to access the X server. It is necessary for GUI applications running inside Docker containers to display their graphical interface on the host machine’s display.</p><p><strong>Pull ROS Desktop Environment Image</strong></p><p>Next, pull the ROS desktop environment image from the Docker Hub repository using the following command:</p><pre>docker pull osrf/ros:humble-desktop</pre><p>This command will download the specified ROS desktop environment image, labelled “humble-desktop”, from the official OSRF repository on Docker Hub.</p><p><strong>Develop Docker Compose Configuration</strong></p><p>Professionally structure your Docker environment by creating a Docker Compose configuration file. This file defines the services, networks, and volumes needed for your ROS desktop environment. Utilize Docker Compose to orchestrate the setup and ensure consistency across development environments.</p><ul><li>Create a docker-compose.yml file in your project directory.</li></ul><p><strong>Docker Compose Configuration:</strong></p><p>Below is a suggested Docker Compose configuration that enables NVIDIA GPU support inside Docker while facilitating GUI functionality. Feel free to customize it to suit your specific requirements:</p><pre>version: &#39;3.8&#39; # Specifies the version of the Docker Compose file format<br><br>services:<br>  ros: # Service name<br>    image: osrf/ros:humble-desktop # Specifies the Docker image to use for this service<br>    container_name: ros # Sets the container name to &quot;ros&quot;<br>    network_mode: host # Uses the host&#39;s networking stack (container shares the host&#39;s network)<br>    volumes:<br>      - /tmp/.X11-unix:/tmp/.X11-unix # Mounts the X11 Unix socket for GUI applications<br>      - /etc/localtime:/etc/localtime:ro # Mounts the local timezone file in read-only mode to sync container time<br>      - /dev/:/dev/ # Mounts the /dev directory to access host devices<br>    environment:<br>      - color_prompt=yes # Environment variable for colored prompts<br>      - DISPLAY # Passes the DISPLAY environment variable for X11 forwarding<br>      - TERM # Passes the TERM environment variable for terminal settings<br>      - QT_X11_NO_MITSHM=1 # Prevents MIT-SHM extension usage for X11, useful for remote displays<br>      - DRI_NAME=card1 # Sets the DRI (Direct Rendering Infrastructure) device<br>      - NVIDIA_VISIBLE_DEVICES=all # Makes all NVIDIA devices visible to the container<br>      - NVIDIA_DRIVER_CAPABILITIES=all # Grants all NVIDIA driver capabilities to the container<br>      - __NV_PRIME_RENDER_OFFLOAD=1 # Enables NVIDIA PRIME render offload<br>      - __GLX_VENDOR_LIBRARY_NAME=nvidia # Specifies the GLX vendor library to use (NVIDIA)<br>    tty: true # Allocates a TTY for the container, useful for interactive shells<br>    stdin_open: true # Keeps stdin open to support interactive processes<br>    devices:<br>      - /dev/:/dev/ # Maps the /dev directory to access host devices (repeated for completeness)<br>    deploy:<br>      resources:<br>        reservations:<br>          devices:<br>            - driver: nvidia # Specifies the NVIDIA driver<br>              count: all # Allocates all available GPUs<br>              capabilities: [gpu] # Requests GPU capabilities<br>    runtime: nvidia # Uses the NVIDIA runtime for GPU support</pre><p><strong>Start Docker Container</strong></p><ul><li>Navigate to the directory containing your Docker Compose file.</li><li>Open a terminal window.</li><li>Run the following command to start the Docker container:</li></ul><pre>docker compose up</pre><ul><li>Wait for the container to start. You can monitor the container’s status by running:</li></ul><pre>docker ps</pre><ul><li>Once the container is up and running, you can interact with it as needed. To access the container’s shell, run:</li></ul><pre>docker exec -it [CONTAINER_NAME] bash</pre><ul><li>Launch a GUI application inside the Docker container. For example, you can run the RViz visualization tool:</li></ul><pre># source the ros2 humble <br>source /opt/ros/humble/setup.bash<br><br># run rviz2<br>rviz2</pre><ul><li>Verify that the GUI application launches successfully and that you can interact with it as expected.</li><li>Test any other GUI applications or functionalities within the Docker container to ensure their proper functioning.</li></ul><p>By following these steps, you can seamlessly start and manage your Docker container, allowing you to work with your ROS desktop environment with NVIDIA GPU support efficiently.</p><p><strong>Verify GPU Utilization</strong></p><p>After launching the GUI application, you can verify whether it is utilizing the NVIDIA GPU resources effectively. Here’s how:</p><ul><li>Open a terminal on your host machine.</li><li>Run the following command to check GPU utilization using nvidia-smi:</li></ul><pre>nvidia-smi</pre><ul><li>Look for the process associated with the GUI application (e.g., rviz2) in the list of GPU processes.</li><li>Confirm that the GPU utilization is observed for the GUI application, indicating that it is running on the NVIDIA GPU.</li></ul><p>By monitoring GPU utilization using nvidia-smi, you can ensure that the GUI application within the Docker container is leveraging the full power of the NVIDIA GPU for enhanced performance and efficiency.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46a04046c067" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>