如何在Linux Docker容器中运行GUI应用程序?
是否有任何图像设置vncserver或其他东西,以便您可以-例如-在Firefox周围添加额外的加速沙箱?
如何在Linux Docker容器中运行GUI应用程序?
是否有任何图像设置vncserver或其他东西,以便您可以-例如-在Firefox周围添加额外的加速沙箱?
当前回答
http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/上给出的解决方案似乎是在容器内启动GUI应用程序的一种简单方法(我尝试在ubuntu 14.04上使用firefox),但我发现需要对作者发布的解决方案进行一个小小的额外更改。
具体来说,对于运行容器,作者已经提到:
docker run -ti --rm \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
firefox
但我发现(根据同一网站上的一个特定评论)有两个额外的选项
-v $HOME/.Xauthority:$HOME/.Xauthority
and
-net=host
需要在运行容器时指定,以便firefox正常工作:
docker run -ti --rm \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $HOME/.Xauthority:$HOME/.Xauthority \
-net=host \
firefox
我已经创建了一个docker映像,其中包含该页面的信息和这些额外的发现:https://hub.docker.com/r/amanral/ubuntu-firefox/
其他回答
你可以简单地安装一个vncserver和Firefox:)
我推了一个图像,vnc/firefox,在这里:docker拉creack/firefox-vnc
图片是用Dockerfile制作的:
# Firefox over VNC
#
# VERSION 0.1
# DOCKER-VERSION 0.2
FROM ubuntu:12.04
# Make sure the package repository is up to date
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
# Install vnc, xvfb in order to create a 'fake' display and firefox
RUN apt-get install -y x11vnc xvfb firefox
RUN mkdir ~/.vnc
# Setup a password
RUN x11vnc -storepasswd 1234 ~/.vnc/passwd
# Autostart firefox (might not be the best way to do it, but it does the trick)
RUN bash -c 'echo "firefox" >> /.bashrc'
这将创建一个运行VNC的Docker容器,密码为1234:
对于Docker 18或更新版本:
docker run -p 5900:5900 -e HOME=/ creack/firefox-vnc x11vnc -forever -usepw -create
对于Docker 1.3或更新版本:
docker run -p 5900 -e HOME=/ creack/firefox-vnc x11vnc -forever -usepw -create
对于1.3版本之前的Docker:
docker run -p 5900 creack/firefox-vnc x11vnc -forever -usepw -create
对于使用Nvidia驱动程序的OpenGL渲染,请使用以下图像:
https://github.com/thewtex/docker-opengl-nvidia
对于其他OpenGL实现,确保映像具有与主机相同的实现。
我刚刚发现了这篇博客,想在这里与你们分享,因为我认为这是最好的方法,而且很简单。
http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/
优点: + docker容器中没有x服务器的东西 +不需要VNC客户端/服务器 + SSH不支持x转发 +更小的docker容器
缺点: 在主机上使用x(不是为了安全沙箱)
以防链接有一天会失败,我把最重要的部分放在这里: dockerfile:
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y firefox
# Replace 1000 with your user / group id
RUN export uid=1000 gid=1000 && \
mkdir -p /home/developer && \
echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
echo "developer:x:${uid}:" >> /etc/group && \
echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
chmod 0440 /etc/sudoers.d/developer && \
chown ${uid}:${gid} -R /home/developer
USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox
构建映像:
docker build -t firefox .
run命令:
docker run -ti --rm \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
firefox
当然,你也可以在运行命令中使用sh -c "echo script-here"
提示:音频请查看:https://stackoverflow.com/a/28985715/2835523
具有BRIDGE网络的Docker。 Ubuntu 16.04使用显示管理器lightdm:
cd /etc/lightdm/lightdm.conf.d
sudo nano user.conf
[Seat:*]
xserver-allow-tcp=true
xserver-command=X -listen tcp
您可以使用更多的私有权限
xhost +
docker run --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --env="DISPLAY=$HOST_IP_IN_BRIDGE_NETWORK:0" --net=bridge $container_name
这不是轻量级的,但是一个很好的解决方案,使docker特性与完整的桌面虚拟化相同。Ubuntu和CentOS的Xfce4或IceWM都可以工作,noVNC选项可以通过浏览器轻松访问。
https://github.com/ConSol/docker-headless-vnc-container
它运行noVNC以及tigerVNC的vncserver。然后它为给定的窗口管理器调用startx。此外,libss_wrapper . dll。用于模拟用户的密码管理。