且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

你可以在 Linux Docker 容器中运行 GUI 应用程序吗?

更新时间:2022-06-22 02:47:34

你可以简单地安装一个 vncserver 和 Firefox :)

You can simply install a vncserver along with Firefox :)

我推送了一个镜像,vnc/firefox,在这里:docker pull creack/firefox-vnc

I pushed an image, vnc/firefox, here: docker pull creack/firefox-vnc

图像是用这个 Dockerfile 制作的:

The image has been made with this 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:

This will create a Docker container running VNC with the password 1234:

对于 Docker 18 或更高版本:

For Docker version 18 or newer:

docker run -p 5900:5900 -e HOME=/ creack/firefox-vnc x11vnc -forever -usepw -create

对于 Docker 1.3 或更新版本:

For Docker version 1.3 or newer:

docker run -p 5900 -e HOME=/ creack/firefox-vnc x11vnc -forever -usepw -create

对于 1.3 版之前的 Docker:

For Docker before version 1.3:

docker run -p 5900 creack/firefox-vnc x11vnc -forever -usepw -create