How to run tkinter inside a docker container on MacBook Pro?
I made a little docker image with xeyes
in it to test X11 clients with the XQuartz X11 server on my Mac using this as my Dockerfile
:
# Base Image
FROM alpine:latest
RUN apk update && \
apk add --no-cache xeyes
# Set a working directory
WORKDIR /work
# Start a shell by default
CMD ["ash"]
And then I built it like this:
docker build -t setchell/xeyes .
And I run it with this:
# Prerequisites
# brew cask install xquartz
# Set your Mac IP address
IP=$(/usr/sbin/ipconfig getifaddr en0)
# Allow connections from Mac to XQuartz
/opt/X11/bin/xhost + "$IP"
# Run container
docker run -it -e DISPLAY="${IP}:0" -v /tmp/.X11-unix:/tmp/.X11-unix setchell/xeyes
And once in the container, I just run:
xeyes
And here is the result:
There may well be simpler ways, and some steps may be unnecessary and if anyone knows a simpler method, please ping me. I'm always happy to learn.