Can you run GUI applications in a Docker container?

前端 未结 22 2503
南旧
南旧 2020-11-22 06:12

How can you run GUI applications in a Docker container?

Are there any images that set up vncserver or something so that you can - for example - add an e

22条回答
  •  心在旅途
    2020-11-22 06:40

    With docker data volumes it's very easy to expose xorg's unix domain socket inside the container.

    For example, with a Dockerfile like this:

    FROM debian
    RUN apt-get update
    RUN apt-get install -qqy x11-apps
    ENV DISPLAY :0
    CMD xeyes
    

    You could do the following:

    $ docker build -t xeyes - < Dockerfile
    $ XSOCK=/tmp/.X11-unix/X0
    $ docker run -v $XSOCK:$XSOCK xeyes
    

    This of course is essentially the same as X-forwarding. It grants the container full access to the xserver on the host, so it's only recommended if you trust what's inside.

    Note: If you are concerned about security, a better solution would be to confine the app with mandatory- or role-based-access control. Docker achieves pretty good isolation, but it was designed with a different purpose in mind. Use AppArmor, SELinux, or GrSecurity, which were designed to address your concern.

提交回复
热议问题