Running GUI apps with Docker


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


I’ve been doing all of my real (paid) work on VMs / containers for a while now but when it comes to writing Java code for some projects for university I stillneed to move away from using vim and install some full blown IDE in order to beproductive. This has been bothering me for quite some time but this week Iwas finally able put the pieces together to run NetBeans in a Docker container so that I can avoidinstalling a lot of Java stuff on my machine that I don’t use on a daily basis.

There are a few different options to run GUI applications inside a Dockercontainer like using SSH with X11 forwarding,or VNC but the simplest one that Ifigured out was to share my X11 socket with the container and use it directly.

The idea is pretty simple and you can easily it give a try by running a Firefoxcontainer using the following Dockerfile as a starting point:

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 . it and run the container with:

docker run -ti --rm \
       -e DISPLAY=$DISPLAY \
       -v /tmp/.X11-unix:/tmp/.X11-unix \
       firefox

If all goes well you should see Firefox running from within a Docker container.

Getting a NetBeans container up and running

Preparing a NetBeans base image was not that straightforward since we need toinstall some additional dependencies (namely the libxext-dev, libxrender-devand libxtst-dev packages) in order to get it to connect to the X11 socketproperly. I also had trouble using OpenJDK and had to switch to Oracle’s Javafor it to work.

After lots of trial and error, I was finally able to make it work and the resultis a base image available at the Docker Hubwith sources on GitHub.

Here’s a quick demo of it in action:

Future work

Over the next few months I’ll be working on a Play!app and will hopefully write a blog post on the workflow I used. Stay tunned for more :)


PS: This approach of sharing the X11 socket also be applied to vagrant-lxccontainers and I’ll document that on the project’s Wiki when Ihave a chance.


posted @   张同光  阅读(145)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示