Docker与GUI应用程序(Docker with GUI application)

编程入门 行业动态 更新时间:2024-10-12 01:25:51
Docker与GUI应用程序(Docker with GUI application)

TL; DR

我需要从Docker容器中后台运行的Java应用程序启动Selenium。 启动失败是因为在运行时期间无法访问X11环境。 请参阅下面我开始的Dockerfile 。

我该怎么办?

问题

我从一个简单的Dockerfile ,安装Java 8和Jetty 9.3.x来运行一个简单的服务(实际上是Selenium的东西)。 该服务实际上是为了启动一些需要UI才能执行的东西。 我遇到的问题是,由于UI在我运行的配置中不可用,因此其中任何内容的执行都会失败。 我还有其他一些与supervisord运行的东西,但这是基本的设置:

Dockerfile

FROM ubuntu:16.04 RUN apt-get update -y && \ apt-get install -y software-properties-common wget supervisor && \ mkdir -p /var/log/supervisor && \ mkdir -p /etc/supervisor/conf.d RUN useradd -Ums /bin/bash jetty RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \ add-apt-repository -y ppa:webupd8team/java && \ apt-get update && \ apt-get install -y oracle-java8-installer && \ rm -rf /var/lib/apt/lists/* && \ rm -rf /var/cache/oracle-jdk8-installer ENV JAVA_HOME /usr/lib/jvm/java-8-oracle ENV JETTY_VERSION "9.3.7.v20160115" ENV JETTY_HOME "/opt/jetty" RUN wget -q -O /opt/jetty.tgz "http://download.eclipse.org/jetty/${JETTY_VERSION}/dist/jetty-distribution-${JETTY_VERSION}.tar.gz" && \ cd /opt && \ tar -zxvf /opt/jetty.tgz && \ rm /opt/jetty.tgz && \ mv "/opt/jetty-distribution-${JETTY_VERSION}" "${JETTY_HOME}" && \ chown -R jetty:jetty "${JETTY_HOME}" ADD supervisor.conf /etc/supervisor.conf ADD jetty.sv.conf /etc/supervisor/conf.d/jetty.sv.conf CMD ["supervisord", "-c", "/etc/supervisor.conf"]

jetty.sv.conf

[program:jetty] command=/usr/bin/java -jar /opt/jetty/start.jar jetty.home=/opt/jetty jetty.base=/opt/jetty redirec_stderr=true startsecs=5

我想确保一切都在UI环境中运行,而不是在无头环境中运行。

我试过的

我尝试使用VNC和共享桌面设置,如下所示:

你能在docker容器中运行GUI应用程序吗? https://github.com/dockerfile/ubuntu-desktop https://github.com/fcwu/docker-ubuntu-vnc-desktop https://hub.docker.com/r/dorowu/ubuntu-desktop-lxde-vnc/ https://blog.docker.com/2013/07/docker-desktop-your-desktop-over-ssh-running-inside-of-a-docker-container/ 构建完整的Ubuntu桌面docker镜像 http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/

但是,这仍然不允许我的Java应用程序执行GUI应用程序。 像往常一样,我确信我在这里缺少一些简单的东西。

如何通过访问UI来执行Jetty容器?

TL;DR

I need to kick off Selenium from a Java application running in the background in a Docker container. The kick off fails because the X11 environment is not accessible during runtime. See Dockerfile below that I am starting with.

What should I do?

Problem

I am starting with a simple Dockerfile that installs Java 8 and Jetty 9.3.x to run a simple service (Selenium stuff, actually). The service is actually set up to kick off some things that require a UI in order to execute. The problem I am having is that the execution of anything in there fails because the UI is not available in the configuration I have running. I have some other things running with supervisord, but this is the basic setup:

Dockerfile

FROM ubuntu:16.04 RUN apt-get update -y && \ apt-get install -y software-properties-common wget supervisor && \ mkdir -p /var/log/supervisor && \ mkdir -p /etc/supervisor/conf.d RUN useradd -Ums /bin/bash jetty RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \ add-apt-repository -y ppa:webupd8team/java && \ apt-get update && \ apt-get install -y oracle-java8-installer && \ rm -rf /var/lib/apt/lists/* && \ rm -rf /var/cache/oracle-jdk8-installer ENV JAVA_HOME /usr/lib/jvm/java-8-oracle ENV JETTY_VERSION "9.3.7.v20160115" ENV JETTY_HOME "/opt/jetty" RUN wget -q -O /opt/jetty.tgz "http://download.eclipse.org/jetty/${JETTY_VERSION}/dist/jetty-distribution-${JETTY_VERSION}.tar.gz" && \ cd /opt && \ tar -zxvf /opt/jetty.tgz && \ rm /opt/jetty.tgz && \ mv "/opt/jetty-distribution-${JETTY_VERSION}" "${JETTY_HOME}" && \ chown -R jetty:jetty "${JETTY_HOME}" ADD supervisor.conf /etc/supervisor.conf ADD jetty.sv.conf /etc/supervisor/conf.d/jetty.sv.conf CMD ["supervisord", "-c", "/etc/supervisor.conf"]

jetty.sv.conf

[program:jetty] command=/usr/bin/java -jar /opt/jetty/start.jar jetty.home=/opt/jetty jetty.base=/opt/jetty redirec_stderr=true startsecs=5

I want to ensure that everything runs in a UI environment rather than in the headless environment.

What I Tried

I tried using the VNC and shared desktop setup as in these:

Can you run GUI apps in a docker container? https://github.com/dockerfile/ubuntu-desktop https://github.com/fcwu/docker-ubuntu-vnc-desktop https://hub.docker.com/r/dorowu/ubuntu-desktop-lxde-vnc/ https://blog.docker.com/2013/07/docker-desktop-your-desktop-over-ssh-running-inside-of-a-docker-container/ Build a full Ubuntu desktop docker image http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/

However, this still doesn't allow my Java application to execute GUI applications. As usual, I'm sure I'm missing something simple here.

How can I execute the Jetty container with access to the UI?

最满意答案

我们几乎有同样的情况。 Bamboo是CI / CD工具,selenium和java8是回归测试的工具,所有这些都在docker容器内运行。 所以我可以说它是100%可能的。

可能对你有帮助的是xvbf(无头X-server)和x11vnc(vnc-server,看看容器内部究竟发生了什么)

RUN set -x &&\ apt-get update &&\ apt-get install -y xvfb x11vnc &&\ apt-get clean autoremove &&\ mkdir ~/.vnc/ && x11vnc -storepasswd 111222 ~/.vnc/passwd &&\ echo "export DISPLAY=:0" >> ~/.bashrc

如果你愿意,你也可以安装firefox

RUN set -x\ && curl -O https://ftp.mozilla.org/pub/firefox/releases/47.0.1/linux-x86_64/ru/firefox-47.0.1.tar.bz2\ && tar xvjf firefox-47.0.1.tar.bz2 -C /usr/local/src\ && rm -rf firefox-47.0.1.tar.bz2\ && ln -s /usr/local/src/firefox/firefox /usr/local/bin/firefox

还要将此命令添加到启动向导或入口点脚本

source ~/perl5/perlbrew/etc/bashrc rm -f /tmp/.X10-lock Xvfb :0 -screen 0 1600x1200x24 & firefox -height 1200 -width 1600 & x11vnc -usepw -forever -shared &

在您启动容器之后,您将能够通过任何vnc客户端连接到此容器,并查看firefox欢迎页面或webtests如何运行,以防它们运行。

We have almost the same case. Bamboo is CI/CD tool, selenium and java8 is tool for regression tests, and all these are running inside of a docker container. So I can say that it is 100% possible.

What probably can help you is xvbf (headless X-server) and x11vnc (vnc-server to see what actually happening inside of container)

RUN set -x &&\ apt-get update &&\ apt-get install -y xvfb x11vnc &&\ apt-get clean autoremove &&\ mkdir ~/.vnc/ && x11vnc -storepasswd 111222 ~/.vnc/passwd &&\ echo "export DISPLAY=:0" >> ~/.bashrc

If you want, you can also install firefox

RUN set -x\ && curl -O https://ftp.mozilla.org/pub/firefox/releases/47.0.1/linux-x86_64/ru/firefox-47.0.1.tar.bz2\ && tar xvjf firefox-47.0.1.tar.bz2 -C /usr/local/src\ && rm -rf firefox-47.0.1.tar.bz2\ && ln -s /usr/local/src/firefox/firefox /usr/local/bin/firefox

Also add this command to startup wizard or entrypoint script

source ~/perl5/perlbrew/etc/bashrc rm -f /tmp/.X10-lock Xvfb :0 -screen 0 1600x1200x24 & firefox -height 1200 -width 1600 & x11vnc -usepw -forever -shared &

As result after you start container, you will be able to connet to this container through any vnc client and see firefox welcome page, or how webtests go, in case they are running.

更多推荐

本文发布于:2023-08-07 16:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464736.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Docker   GUI   application

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!