Skip to content

Instantly share code, notes, and snippets.

@RishikesavanRamesh
Last active October 6, 2025 03:28
Show Gist options
  • Select an option

  • Save RishikesavanRamesh/d8c085c958bc11e8562cd3db297e4eb8 to your computer and use it in GitHub Desktop.

Select an option

Save RishikesavanRamesh/d8c085c958bc11e8562cd3db297e4eb8 to your computer and use it in GitHub Desktop.
Using Xephyr for Secure Docker GUI Access

Using Xephyr for Secure Docker GUI Access

When working with ROS development in Docker containers, visualizing data using tools like rviz2 can be challenging due to X11 authentication issues, especially after system restarts. The following approach uses Xephyr to securely manage GUI access without compromising the security of your host's X server.

Overview

  • Challenge: X11 authentication issues and security concerns when using Docker containers with GUI applications.
  • Solution: Use Xephyr to create a nested X server for Docker container GUI applications.

Steps to Set Up Xephyr for Docker GUI Applications

  • Start Xephyr: Open a terminal on your host machine and run:

    Xephyr :7 -screen 1920x1080 -extension MIT-SHM -extension XTEST &

    This starts Xephyr as a nested X server on display :7, with shared memory and test extensions disabled.

  • Run Docker Container: In the same terminal or a new one, run your Docker container with the following command:

    docker run --rm -it -e DISPLAY=:7 -v /tmp/.X11-unix/:/tmp/.X11-unix/:rw ros /bin/bash

    This command ensures that the Docker container uses the Xephyr display for its GUI applications.

Why This Approach?

  • Security: By using Xephyr, you avoid the security risks of using xhost +SI:localuser:$USER, which allows any Docker container with the same UID/GID as the host to access the X server. Xephyr provides a more controlled and isolated environment.
  • Convenience: The use of a disposable X server (Xephyr) eliminates the need to share X11 authentication secrets (xauth) between the host and the container. This avoids issues related to authentication after system restarts and simplifies GUI access management.

Notes

  • Ensure Xephyr and Docker are installed on your host machine.
  • Adjust the -screen parameter in the Xephyr command as needed for your display resolution.
  • The :7 display number can be changed if needed, but make sure it matches between the Xephyr and Docker commands.

This guide will help you securely manage GUI applications in Docker containers using Xephyr, while conveniently handling X11 authentication issues. Feel free to adjust the settings as per your development needs.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment