-2

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?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
stdcerr
  • 13,725
  • 25
  • 71
  • 128
  • 2
    This answer may help with the first problem, the container has no x server to use: https://stackoverflow.com/a/28395350/3903479. In order to keep packages and config you'll likely want to install the required packages in the `Dockerfile`, this answer has a little more info https://stackoverflow.com/a/52015087/3903479 – GammaGames Aug 30 '19 at 22:19
  • One question to a question, please. Asking how to persist state in your container should not be in the same question as asking how to run X. – Charles Duffy Aug 30 '19 at 22:52
  • (That said, if you're doing software installations interactively in your Docker container rather than from the Dockerfile, Docker may not be the right tool for your needs). – Charles Duffy Aug 30 '19 at 23:00
  • 1
    `exec`'ing into a running container and installing software is imperative (do this, do that), keeping your instructions in a `Dockerfile` is declarative (give me this). In an imperative system, if a task is interrupted, a container dies, you need to restart from scratch cf. in a declarative system if the container dies you run a new container. – masseyb Aug 31 '19 at 00:05

1 Answers1

2

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).

masseyb
  • 3,745
  • 1
  • 17
  • 29