translated

This commit is contained in:
geekpi 2017-10-25 08:47:37 +08:00
parent 6e7f613011
commit 7e1ee488d2
2 changed files with 113 additions and 144 deletions

View File

@ -1,144 +0,0 @@
translating---geekpi
Why Use Docker with R? A DevOps Perspective
============================================================
[![opencpu logo](https://i1.wp.com/www.opencpu.org/images/stockplot.png?w=456&ssl=1)][11]
There have been several blog posts going around about why one would use Docker with R.
In this post Ill try to add a DevOps point of view and explain how containerizing
R is used in the context of the OpenCPU system for building and deploying R servers.
> Has anyone in the [#rstats][2] world written really well about the *why* of their use of Docker, as opposed to the the *how*?
>
> — Jenny Bryan (@JennyBryan) [September 29, 2017][3]
### 1: Easy Development
The flagship of the OpenCPU system is the [OpenCPU server][12]:
a mature and powerful Linux stack for embedding R in systems and applications.
Because OpenCPU is completely open source we can build and ship on DockerHub. A ready-to-go linux server with both OpenCPU and RStudio
can be started using the following (use port 8004 or 80):
```
docker run -t -p 8004:8004 opencpu/rstudio
```
Now simply open [http://localhost:8004/ocpu/][13] and
[http://localhost:8004/rstudio/][14] in your browser!
Login via rstudio with user: `opencpu` (passwd: `opencpu`) to build or install apps.
See the [readme][15] for more info.
Docker makes it easy to get started with OpenCPU. The container gives you the full
flexibility of a Linux box, without the need to install anything on your system.
You can install packages or apps via rstudio server, or use `docker exec` to a
root shell on the running server:
```
# Lookup the container ID
docker ps
# Drop a shell
docker exec -i -t eec1cdae3228 /bin/bash
```
From the shell you can install additional software in the server, customize the apache2 httpd
config (auth, proxies, etc), tweak R options, optimize performance by preloading data or
packages, etc.
### 2: Shipping and Deployment via DockerHub
The most powerful use if Docker is shipping and deploying applications via DockerHub. To create a fully standalone
application container, simply use a standard [opencpu image][16]
and add your app.
For the purpose of this blog post I have wrapped up some of the [example apps][17] as docker containers by adding a very simple `Dockerfile` to each repository. For example the [nabel][18] app has a [Dockerfile][19] that contains the following:
```
FROM opencpu/base
RUN R -e 'devtools::install_github("rwebapps/nabel")'
```
It takes the standard [opencpu/base][20]
image and then installs the nabel app from the Github [repository][21].
The result is a completeley isolated, standalone application. The application can be
started by anyone using e.g:
```
docker run -d 8004:8004 rwebapps/nabel
```
The `-d` daemonizes on port 8004.
Obviously you can tweak the `Dockerfile` to install whatever extra software or settings you need
for your application.
Containerized deployment shows the true power of docker: it allows for shipping fully
self contained appliations that work out of the box, without installing any software or
relying on paid hosting services. If you do prefer professional hosting, there are
many companies that will gladly host docker applications for you on scalable infrastructure.
### 3 Cross Platform Building
There is a third way Docker is used for OpenCPU. At each release we build
the `opencpu-server` installation package for half a dozen operating systems, which
get published on [https://archive.opencpu.org][22].
This process has been fully automated using DockerHub. The following images automatically
build the enitre stack from source:
* [opencpu/ubuntu-16.04][4]
* [opencpu/debian-9][5]
* [opencpu/fedora-25][6]
* [opencpu/fedora-26][7]
* [opencpu/centos-6][8]
* [opencpu/centos-7][9]
DockerHub automatically rebuilds this images when a new release is published on Github.
All that is left to do is run a [script][23]
which pull down the images and copies the `opencpu-server`binaries to the [archive server][24].
--------------------------------------------------------------------------------
via: https://www.r-bloggers.com/why-use-docker-with-r-a-devops-perspective/
作者:[Jeroen Ooms][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.r-bloggers.com/author/jeroen-ooms/
[1]:https://www.opencpu.org/posts/opencpu-with-docker/
[2]:https://twitter.com/hashtag/rstats?src=hash&ref_src=twsrc%5Etfw
[3]:https://twitter.com/JennyBryan/status/913785731998289920?ref_src=twsrc%5Etfw
[4]:https://hub.docker.com/r/opencpu/ubuntu-16.04/
[5]:https://hub.docker.com/r/opencpu/debian-9/
[6]:https://hub.docker.com/r/opencpu/fedora-25/
[7]:https://hub.docker.com/r/opencpu/fedora-26/
[8]:https://hub.docker.com/r/opencpu/centos-6/
[9]:https://hub.docker.com/r/opencpu/centos-7/
[10]:https://www.r-bloggers.com/
[11]:https://www.opencpu.org/posts/opencpu-with-docker
[12]:https://www.opencpu.org/download.html
[13]:http://localhost:8004/ocpu/
[14]:http://localhost:8004/rstudio/
[15]:https://hub.docker.com/r/opencpu/rstudio/
[16]:https://hub.docker.com/u/opencpu/
[17]:https://www.opencpu.org/apps.html
[18]:https://rwebapps.ocpu.io/nabel/www/
[19]:https://github.com/rwebapps/nabel/blob/master/Dockerfile
[20]:https://hub.docker.com/r/opencpu/base/
[21]:https://github.com/rwebapps
[22]:https://archive.opencpu.org/
[23]:https://github.com/opencpu/archive/blob/gh-pages/update.sh
[24]:https://archive.opencpu.org/
[25]:https://www.r-bloggers.com/author/jeroen-ooms/

View File

@ -0,0 +1,113 @@
为什么要在 Docker 中使用 R 一位 DevOps 的视角
============================================================
[![opencpu logo](https://i1.wp.com/www.opencpu.org/images/stockplot.png?w=456&ssl=1)][11]
有几篇关于为什么要在 Docker 中使用 R 的文章。在这篇文章中,我将尝试加入一个 DevOps 的观点,并解释在 OpenCPU 系统的上下文中如何使用容器化 R 来构建和部署 R 服务器。
> 有在 [#rstats][2] 世界的人真正地写*为什么*他们使用 Docker而不是*如何*么?
>
> — Jenny Bryan (@JennyBryan) [September 29, 2017][3]
### 1轻松开发
OpenCPU 系统的旗舰是[ OpenCPU 服务器][12]:它是一个成熟且强大的 Linux 栈,用于在系统和应用程序中嵌入 R。因为 OpenCPU 是完全开源的,我们可以在 DockerHub 上构建和发布。可以使用以下命令启动使用端口8004或80一个可以立即使用的 OpenCPU 和 RStudio 的 Linux 服务器:
```
docker run -t -p 8004:8004 opencpu/rstudio
```
现在只需在你的浏览器打开 [http://localhost:8004/ocpu/][13] 和 [http://localhost:8004/rstudio/][14]!在 rstudio 中用用户 `opencpu`(密码:`opencpu`)登录来构建或安装应用程序。有关详细信息,请参阅[自述文件][15]。
Docker 让开始使用 OpenCPU 变得简单。容器给你一个充分灵活的 Linux而无需在系统上安装任何东西。你可以通过 rstudio 服务器安装软件包或应用程序,也可以使用 `docker exec` 到正在运行的服务器中的 root shell 中:
```
# Lookup the container ID
docker ps
# Drop a shell
docker exec -i -t eec1cdae3228 /bin/bash
```
你可以在服务器的 shell 中安装其他软件,自定义 apache2 httpd 配置auth代理等调整 R 选项,通过预加载数据或包等来优化性能。
### 2 通过 DockerHub 发布和部署
最强大的是Docker 可以通过 Dockerhub 发布和部署。要创建一个完全独立的应用程序容器,只需使用标准[ opencpu 镜像][16]并添加你的程序。
为了本文的目的,我通过在每个仓库中添加一个非常简单的 “Dockerfile” 将一些[示例程序][17]打包为 docker 容器。例如:[nabel][18] 的 [Dockerfile][19] 包含以下内容:
```
FROM opencpu/base
RUN R -e 'devtools::install_github("rwebapps/nabel")'
```
它采用标准的 [opencpu/base][20] 镜像,并从 Github [仓库][21]安装 nabel。结果是一个完全隔离独立的程序。任何人可以使用下面这样的命令启动程序
```
docker run -d 8004:8004 rwebapps/nabel
```
`-d` 代表守护进程监听 8004 端口。很显然,你可以调整 `Dockerfile` 来安装任何其他的软件或设置你需要的程序。
容器化部署展示了 Docker 的真正能力:它可以发布可以开箱即用的独立软件,而无需安装任何软件或依赖付费托管服务。如果你更喜欢专业的托管,那会有许多公司乐意在可扩展的基础设施上为你托管 docker 程序。
### 3 跨平台构建
Docker用于OpenCPU的第三种方式。每次发布我们都构建 6 个操作系统的 `opencpu-server` 安装包,它们在 [https://archive.opencpu.org][22] 上公布。这个过程已经使用 DockerHub 完全自动化了。以下镜像从源代码自动构建所有栈:
* [opencpu/ubuntu-16.04][4]
* [opencpu/debian-9][5]
* [opencpu/fedora-25][6]
* [opencpu/fedora-26][7]
* [opencpu/centos-6][8]
* [opencpu/centos-7][9]
当 Github 上发布新版本时DockerHub 会自动重建此镜像。要做的就是运行一个[脚本][23],它会取回镜像并将 `opencpu-server` 二进制复制到[归档服务器上][24]。
--------------------------------------------------------------------------------
via: https://www.r-bloggers.com/why-use-docker-with-r-a-devops-perspective/
作者:[Jeroen Ooms][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.r-bloggers.com/author/jeroen-ooms/
[1]:https://www.opencpu.org/posts/opencpu-with-docker/
[2]:https://twitter.com/hashtag/rstats?src=hash&ref_src=twsrc%5Etfw
[3]:https://twitter.com/JennyBryan/status/913785731998289920?ref_src=twsrc%5Etfw
[4]:https://hub.docker.com/r/opencpu/ubuntu-16.04/
[5]:https://hub.docker.com/r/opencpu/debian-9/
[6]:https://hub.docker.com/r/opencpu/fedora-25/
[7]:https://hub.docker.com/r/opencpu/fedora-26/
[8]:https://hub.docker.com/r/opencpu/centos-6/
[9]:https://hub.docker.com/r/opencpu/centos-7/
[10]:https://www.r-bloggers.com/
[11]:https://www.opencpu.org/posts/opencpu-with-docker
[12]:https://www.opencpu.org/download.html
[13]:http://localhost:8004/ocpu/
[14]:http://localhost:8004/rstudio/
[15]:https://hub.docker.com/r/opencpu/rstudio/
[16]:https://hub.docker.com/u/opencpu/
[17]:https://www.opencpu.org/apps.html
[18]:https://rwebapps.ocpu.io/nabel/www/
[19]:https://github.com/rwebapps/nabel/blob/master/Dockerfile
[20]:https://hub.docker.com/r/opencpu/base/
[21]:https://github.com/rwebapps
[22]:https://archive.opencpu.org/
[23]:https://github.com/opencpu/archive/blob/gh-pages/update.sh
[24]:https://archive.opencpu.org/
[25]:https://www.r-bloggers.com/author/jeroen-ooms/