Docker与GUI应用程序 [英] Docker with GUI application

查看:277
本文介绍了Docker与GUI应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR



我需要从Docker容器的背景中运行的Java应用程序启动Selenium。启动失败,因为X11环境在运行时无法访问。



我该怎么办?

/ p>

问题



我从一个简单的开始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& amp;& \
mkdir -p /etc/supervisor/conf.d

RUN useradd -Ums / bin / bash jetty

RUN echo oracle-java8-installer shared / accepted-oracle-license-v1-1选择true | debconf-set-choices&& \
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_VERSION9.3.7.v20160115
ENV JETTY_HOME/ opt / jetty

RUN wget -q -O /opt/jetty.tgzhttp://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]
/ pre>

jetty.sv.conf

  [程序: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-ofa-a-a-a- docker-container /

  • 构建完整的Ubuntu桌面Docker映像

  • http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/



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



    如何执行Jetty容器访问UI?

    解决方案

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



    可能有什么可以帮助你的是xvbf(无头X服务器)和x11vnc(vnc-server来查看实际发生的情况在容器内)

     运行set -x&& \ 
    apt-get update&& \
    apt-get install -y xvfb x11vnc& \
    apt-get clean autoremove& \
    mkdir〜/ .vnc /&& x11vnc -storepasswd 111222〜/ .vnc / passwd&& \
    echoexport DISPLAY =:0>> 〜/ .bashrc

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

     运行set -x\ 
    && curl -O https://ftp.mozilla.org/pub/firefox/releases/47.0.1/linux-x86_64/ru/firefox-47.0.1.tar.bz2\
    & amp;& 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

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

      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欢迎页面,或Webtest测试如何运行,以防万一它们正在运行。


    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:

    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?

    解决方案

    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.

    这篇关于Docker与GUI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆