why can i not run a X11 application?

2020-01-20 12:18发布

问题:

So, as the title states, I'm a docker newbie. I downloaded and installed the archlinux/base container which seems to work great so far. I've setup a few things, and installed some packages (including xeyes) and I now would like to launch xeyes. For that I found out the CONTAINER ID by running docker ps and then used that ID in my exec command which looks now like:

$ docker exec -it -e DISPLAY=$DISPLAY 4cae1ff56eb1 xeyes
Error: Can't open display: :0

Why does it still not work though? Also, how can I stop my running instance without losing its configured state? Previously I have exited the container and all my configuration and software installations were gone when I restarted it. That was not desired. How do I handle this correctly?

回答1:

Concerning the X Display you need to share the xserver socket (note: docker can't bind mount a volume during an exec) and set the $DISPLAY (example Dockerfile):

FROM archlinux/base

RUN pacman -Syyu --noconfirm xorg-xeyes

ENTRYPOINT ["xeyes"]

Build the docker image: docker build --rm --network host -t so:57733715 .

Run the docker container: docker run --rm -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY so:57733715

Note: in case of No protocol specified errors you could disable host checking with xhost + but there is a warning to that (man xhost for additional information).