Dockerfile文件

 #!/bin/bash
FROM centos:7
RUN yum install -y firefox
####用你自己的 uid /gid 替换下面的0
RUN export uid=0 gid=0
RUN mkdir -p /home/developer
RUN echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash">>/etc/passwd
RUN echo "developer:x:${uid}:">>/etc/group
RUN echo "developer ALL=(ALL) NOPASSWD: ALL">>/etc/sudoers
RUN chmod 0440 /etc/sudoers
RUN chown ${uid}:${gid} -R  /home/developer
USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

注意:在第四行的配置中,用你自己的用户和组id来替换0。 我们可以用下面的命令在shell或者终端中得到uid和gid。

# id $USER

构造Docker容器

# docker build --rm -t firefox .

运行Docker容器

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

The next I tried to run the same container with -u 0 to become root and after i tried to start the application the following error message appears:

No protocol specified
QXcbConnection: Could not connect to display :0
Aborted (core dumped)

The Solution of the problem:

Give docker the rights to access the X-Server with:

#xhost +local:docker