x11docker

repository·master·Indexed 27 days ago

https://github.com/mviereck/x11docker

A tool for running graphical desktop applications and entire desktop environments inside Linux containers (Docker or Podman) while providing a secure X or Wayland display server. It supports GPU hardware acceleration, sound (PipeWire, PulseAudio, ALSA), persistent data via --home and --share, and various display modes including seamless and desktop modes.

Tokens
4.7K
Snippets
12
Records
28
Agent score
42%

What's inside x11docker

  1. Overview of x11docker

    master

    x11docker is a tool designed to run graphical user interface (GUI) applications within GNU/Linux containers using Docker. It bridges the gap between Docker (which is primarily designed for server software) and the need for a display server to render desktop applications.

    Key capabilities include:

    • GUI Support: Executes Desktop GUI applications by running an X display server on the host and providing access to it within the container.
    • Resource Access: Simplifies container setup for accessing host resources such as shared files, GPU acceleration, audio, webcams, and printers.
    • Security: Implements security setups to enhance container isolation from the host system, following the principle of least privilege.
    • Versatility: While developed for GNU/Linux, it can run natively on MS Windows (with limitations) or within a Virtual Linux Machine on MS Windows and macOS.
    • Frontend Options: Includes an optional graphical frontend called x11docker-gui.
  2. Quickstart with x11docker

    master

    To quickly set up and run a GUI application in a container, follow these steps:

    1. Install x11docker using the official installation script:
      curl -fsSL https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | sudo bash -s -- --update
    2. Install dependencies: You must either pull the x11docker/xserver image or install host-side tools like nxagent, xpra, or xephyr.
    3. Run a GUI application: Use the syntax x11docker IMAGENAME [COMMAND].

    Common Examples:

    • Run a specific application: x11docker x11docker/xfce thunar
    • Run a full desktop environment: x11docker --desktop x11docker/xfce
    • Run with GPU hardware acceleration: x11docker --gpu x11docker/xfce glxgears
    curl -fsSL https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | sudo bash -s -- --update
  3. Configure X server dependencies

    master

    x11docker requires an X server. You have two main approaches:

    1. Use the automatic x11docker/xserver image

    This is the easiest method as it provides most optional dependencies and several X servers/Wayland compositors without requiring host installation.

    2. Install dependencies on the host

    If you prefer to use host-side X servers, the recommended base commands to install are: nxagent, Xephyr, weston, Xwayland, xdotool, xauth, xinit, xclip, xhost, xrandr, and xdpyinfo.

  4. Configure X server and Wayland environments

    master

    x11docker automatically selects an X server based on installed dependencies and options like --desktop, --gpu, --wayland, and --xw.

    • Seamless mode (single window on host desktop): Supported via --nxagent or --xpra. Use --hostdisplay as an insecure fallback.
    • Desktop mode (full desktop environment): Use --desktop. x11docker prefers --xephyr or --nxagent.
    • Wayland mode: Use --wayland for a Wayland environment, --weston to run the weston compositor, or --hostwayland for seamless integration with host Wayland desktops (Gnome 3, KDE 5, Sway).
    • Side-by-side X and Wayland: Use --weston-xwayland --wayland or, if on a host Wayland desktop, --hostdisplay --hostwayland.
    • No GUI: Use -t, --tty to run without X or Wayland.
    x11docker --wayland x11docker/xfce xfce4-terminal
  5. Install and update x11docker

    master

    x11docker requires bash and either docker or podman to run. To ensure you have the latest version, use the built-in update commands.

    • To update to the latest stable release: x11docker --update
    • To update to the latest beta: x11docker --update-master
    x11docker --update
  6. Build x11docker images locally

    master

    Because Docker Hub images may become outdated, it is recommended to build images locally using the --build option. You can use existing Dockerfiles from the mviereck GitHub repositories (specifically those starting with dockerfile-x11docker) to build your own images.

    To build a specific image locally, use:

    x11docker --build x11docker/fvwm
  7. Install x11docker

    master

    x11docker is a bash script. You can install it via distribution repositories or manually.

    Manual Installation via Script

    To install or update the latest release from GitHub, use the following commands:

    Using sudo (recommended for system-wide installation):

    curl -fsSL https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | sudo bash -s -- --update

    As root:

    curl -fsSL https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | bash -s -- --update

    Minimal Installation

    You can run x11docker without a full installation by executing the script directly: bash x11docker or ./x11docker. For a manual system-wide setup, make the script executable (chmod +x x11docker) and move it to a directory in your PATH, such as /usr/local/bin.

    curl -fsSL https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | sudo bash -s -- --update
  8. Use presets for command shortcuts

    master

    Create shortcuts for complex option combinations using --preset FILENAME. Presets are stored in ~/.config/x11docker/preset/ or /etc/x11docker/preset/.

    Example Multimedia Preset: Create a file ~/.config/x11docker/preset/multimedia with:

    --gpu
    --webcam
    --printer
    --pipewire
    --clipboard
    --share ~/Videos
    --share ~/Music

    Run it with: x11docker --preset=multimedia jess/vlc

    Default Preset: A file named default in the preset directories acts as a global configuration file for all x11docker sessions (e.g., to always use --backend=podman).

    x11docker --preset=multimedia jess/vlc
  9. Create custom x11docker images using Dockerfiles

    master

    To add custom applications or make persistent changes to an x11docker image, create a new Dockerfile using an existing x11docker image as the base (FROM).

    Example Dockerfile to add VLC to an Xfce desktop:

    # xfce desktop with VLC media player
    FROM x11docker/xfce
    RUN apt-get update && apt-get install -y vlc
  10. Docker Desktop vs Docker Engine for x11docker

    master

    For optimal performance and feature support, use the native Docker Engine Server version (typically provided by packages like docker.io or docker-ce) rather than Docker Desktop.

    Docker Desktop runs Docker inside a QEMU VM, and while x11docker provides experimental support for it, some features may not work. If you use Podman, you do not need to worry about this distinction.

  11. Configure container user and identity

    master

    By default, x11docker uses an unprivileged user similar to your host user. If the application requires a different user:

    1. Check image's predefined user: docker inspect --format '{{.Config.User}}' IMAGENAME
    2. Use the image's user: Use --user=RETAIN to enable the user specified in the image.
    3. Use root: Use --user=root (may require --cap-default).
    docker inspect --format '{{.Config.User}}' IMAGENAME