A helper script for starting an interactive Docker container with X11 forwarding on MacOS. It enables graphical applications running inside the container to display windows on the host machine, such as when you're plotting something in an R or Python REPL.
- Runs containers ephemerally (
--rm
) - Attaches a pseudo-TTY (
--tty
) and runs interactively (--interactive
). - Automatically mounts the current working directory at
/work
. - Automatically sets the correct X11 display variable
(
DISPLAY=docker.for.mac.host.internal:0
). - Ensures XQuartz is running before starting the container.
Clone this repository and place/symlink the docker-X11-interactive.sh
script
in your PATH
, followed by placing/symlinking the xhost-config.sh
script into
~/.xinitrc.d/
, for example:
git clone [email protected]:fasterius/docker-X11-interactive.git
cp docker-X11-interactive.sh ~/.local/bin/
mkdir -p ~/.xinitrc.d && cp xinitrc.d/xhost-config.sh ~/.xinitrc.d
docker-X11-interactive.sh [OPTIONS] IMAGE [ARG...]
IMAGE
(required): The Docker image to runOPTIONS
(optional): Extra flags to pass to docker run (e.g.,--gpus all
)ARG...
(optional): Command to run inside the container (e.g.,python
)
Run an R REPL inside a container:
docker-X11-interactive.sh rocker/tidyverse R
Run a Python REPL inside a container:
docker-X11-interactive.sh python:3.13 python