Merge pull request #2618 from geekpi/master

translated
This commit is contained in:
geekpi 2015-04-11 12:29:15 +08:00
commit 52ac56d12f
2 changed files with 78 additions and 80 deletions

View File

@ -1,80 +0,0 @@
Translating---geekpi
How to Run GUI Apps in a Docker Container
================================================================================
Hi everyone, today we'll learn how we can run GUI Applications inside a [Docker][1] Container. We can easily run most of the common GUI apps without getting into trouble inside a Docker Container. Docker is an Open Source project that provides an open platform to pack, ship and run any application as a lightweight container. It has no boundaries of Language support, Frameworks or packaging system and can be run anywhere, anytime from a small home computers to high-end servers. It makes them great building blocks for deploying and scaling web apps, databases, and back-end services without depending on a particular stack or provider.
Here are the quick and easy steps on how we can run a GUI App in a Docker Container. In this tutorial, we'll take Firefox for the example.
### 1. Installing Docker ###
First of all, before we start, we must ensure that we have Docker installed in our host Linux Operating System. Here, we are running CentOS 7 as host so, we'll be running yum manager to install docker using the below command.
# yum install docker
![](http://blog.linoxide.com/wp-content/uploads/2015/03/installing-docker.png)
# systemctl restart docker.service
### 2. Creating Dockerfile ###
Now, as our Docker Daemon is running, we'll now prepare to create our Firefox Docker Container. We'll create a Dockerfile where we'll enter the required configuration to create a working Firefox Container. We'll fetch latest version of CentOS for our Docker Image. To do so, we'll create a file named Dockerfile using our favorite text editor.
# nano Dockerfile
Then, we'll add the following lines of configuration into Dockerfile and then save it.
#!/bin/bash
FROM centos:7
RUN yum install -y firefox
# Replace 0 with your user / group id
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
![](http://blog.linoxide.com/wp-content/uploads/2015/03/Dockerfile-GUI.png)
**Note: Please replace 0 with your user and group id in 4th line of the configuration. We can get the uid and gid of current user by running the following command in a shell or a terminal.**
# id $USER
![](http://blog.linoxide.com/wp-content/uploads/2015/03/user-id.png)
### 3. Building Docker Container ###
We'll now build the container which will work according to the above Dockerfile. It will install firefox web browser and its required packages. It will then set user permission to make it work. Here, the image name is set as firefox, you can name it as your desire.
# docker build --rm -t firefox .
![](http://blog.linoxide.com/wp-content/uploads/2015/03/building-firefox-docker.png)
### 4. Running Docker Container ###
Now, finally, if everything went cool, we'll be able to run our GUI App ie Mozilla Firefox Browser from inside our firefox Docker Container running in a CentOS 7 Image.
# docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox
### Conclusion ###
Running GUI Apps in a Docker Container is really an awesome experience which will never harm/use your host Filesystem. It is fully dependent on your Docker Container. In this tutorial, we tried Firefox in our CentOS 7 Docker Image with Firefox installed. We can use many more GUI Apps with this technology. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents. Thank you ! Enjoy :-)
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/run-gui-apps-docker-container/
作者:[Arun Pyasi][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://linoxide.com/author/arunp/
[1]:http://docker.io/

View File

@ -0,0 +1,78 @@
如何在Docker容器中运行GUI程序
================================================================================
各位,今天我们将学习如何在[Docker][1]之中运行GUI程序。我们可以轻易地在Docker容器中运行大多数GUI程序且不出错。Docker是一个开源项目提供了一个打包、分发和运行任意程序的轻量级容器的开放平台。它没有语言支持、框架或者打包系统的限制并可以在任何地方、任何时候从小型的家用电脑到高端的服务器都可以运行。这让人们可以打包不同的包用于部署和扩展网络应用数据库和后端服务而不必依赖于特定的栈或者提供商。
下面是我们该如何在Docker容器中运行GUI程序的简单步骤。本教程中我们会用Firefox作为例子。
### 1. 安装 Docker ###
在开始事前我们首先得确保在Linux主机中已经安装了Docker。这里我运行的是CentOS 7 主机我们将运行yum管理器和下面的命令来安装Docker。
# yum install docker
![](http://blog.linoxide.com/wp-content/uploads/2015/03/installing-docker.png)
# systemctl restart docker.service
### 2. 创建 Dockerfile ###
现在Docker守护进程已经在运行中了我们现在准备创建自己的Firefox Docker容器。我们要创建一个Dockerfile这里我们要输入需要的配置来创建一个可以工作的Firefox容器。我们取下CentOS中最新的Docker镜像。至此我们需要用文本编辑器创建一个名为Dockerfile的文件。
# nano Dockerfile
接着在Dockerfile中添加下面的行并保存。
#!/bin/bash
FROM centos:7
RUN yum install -y firefox
# Replace 0 with your user / group id
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
![](http://blog.linoxide.com/wp-content/uploads/2015/03/Dockerfile-GUI.png)
**注意在第四行的配置中用你自己的用户和组id来替换0。 我们可以用下面的命令在shell或者终端中得到uid和gid。**
# id $USER
![](http://blog.linoxide.com/wp-content/uploads/2015/03/user-id.png)
### 3. 构造Docker容器 ###
下面我们就要根据上面的Dockerfile构建一个容器。它会安装firefox浏览器和它需要的包。它接着会设置用户权限并让它可以工作。这里镜像名是firefox你可以根据你的需要命名。
# docker build --rm -t firefox .
![](http://blog.linoxide.com/wp-content/uploads/2015/03/building-firefox-docker.png)
### 4. 运行Docker容器 ###
现在如果一切顺利我们现在可以在运行着CentOS 7镜像的Docker容器中运行我们的GUI程序也就是Firefox浏览器了。
# docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox
### 总结 ###
在Dcoker容器中运行GUI程序是一次很棒的体验它对你的主机文件系统没有任何的伤害。它完全依赖你的Docker容器。本教程中我尝试了CentOS 7 Docker中的Firefox。我们可以用这个技术尝试更多的GUI程序。如果你有任何问题、建议、反馈请在下面的评论栏中写下来这样我们可以提升或更新我们的内容。谢谢
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/run-gui-apps-docker-container/
作者:[Arun Pyasi][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://linoxide.com/author/arunp/
[1]:http://docker.io/