Skip to content

X11 socket volume mounting

X11 socket volume mounting is a technique used to enable applications running inside a [[Docker]] container to render a graphical user interface (GUI) on the host machine's display. This method bypasses network-based forwarding by directly sharing the host's X11 socket file with the container.^[600-developer-docker-run-command.md]

Implementation

To utilize X11 socket volume mounting, two specific configurations are required when executing the docker run command.^[600-developer-docker-run-command.md]

  • Volume Mount (-v): The /tmp/.X11-unix directory on the host must be mounted to the same path inside the container. This directory contains the socket file used for inter-process communication between the X server and its clients.^[600-developer-docker-run-command.md]
  • Environment Variable (-e): The DISPLAY environment variable must be passed to the container. Its value should match the host's display configuration (typically set to $DISPLAY in the host environment) to direct the application's output to the correct screen.^[600-developer-docker-run-command.md]

Command Example

The following command structure demonstrates how to launch a container (e.g., jess/tor-browser) with X11 socket forwarding enabled:^[600-developer-docker-run-command.md]

docker run -it \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e DISPLAY=$DISPLAY \
    --name tor-browser \
    jess/tor-browser
  • [[Docker]]
  • [[Environment variables]]
  • [[Volume mounting]]
  • [[Host machine]]

Sources

^[600-developer-docker-run-command.md]