# Use Ubuntu 22.04 as the base imageFROMubuntu:22.04# Set non-interactive mode for apt-get to avoid promptsENVDEBIAN_FRONTEND=noninteractive
# Update package list and install X11 and OpenGL dependenciesRUNapt-getupdate&&apt-getinstall-y\#CoreX11libraries
libx11-6\libxext6\libxrender1\libxinerama1\libxcursor1\libxrandr2\libxi6\#OpenGL/Mesaforrendering
libgl1-mesa-glx\libgl1-mesa-dri\libglu1-mesa\#UtilitiesforX11authandtesting
xauth\mesa-utils\#apps
cheese\gstreamer1.0-alsa\gstreamer1.0-libav\gstreamer1.0-plugins-bad\gstreamer1.0-plugins-base\gstreamer1.0-plugins-good\gstreamer1.0-plugins-ugly\gstreamer1.0-tools\#Cleanup
&&rm-rf/var/lib/apt/lists/*
# Set up environment variables for X11ENVDISPLAY=:0
# Optional: Define a default runtime directory (can be overridden at runtime)ENVXDG_RUNTIME_DIR=/tmp/runtime-root
# Create a non-root user (optional, for better security and matching host permissions)ARGUSERNAME=user
ARGUID=1000ARGGID=1000# add new sudo userRUNuseradd-m$USERNAME&&\echo"$USERNAME:$USERNAME"|chpasswd&&\usermod--shell/bin/bash$USERNAME&&\usermod-aGsudo$USERNAME&&\usermod-aGvideo$USERNAME&&\usermod-aGdialout$USERNAME&&\mkdir/etc/sudoers.d&&\echo"$USERNAME ALL=(ALL) NOPASSWD:ALL">>/etc/sudoers.d/$USERNAME&&\chmod0440/etc/sudoers.d/$USERNAME&&\usermod--uid$UID$USERNAME&&\groupmod--gid$GID$USERNAME# Switch to the non-root user# USER $USERNAME# Set working directoryWORKDIR/home/$USERNAME# Default command (can be overridden)CMD["bash"]
The command xhost +local:docker is used on Linux systems to manage access control for the X11 display server.
Allows any process running locally as part of the "docker" context (Docker containers) to connect to your X server.