如何在 docker 中加快 R 包的安装速度 [英] How to speed up R packages installation in docker

查看:24
本文介绍了如何在 docker 中加快 R 包的安装速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有以下要为 docker 映像安装的软件包列表

Say you have the following list of packages you would like to install for a docker image

("jsonlite","dplyr","stringr","tidyr","lubridate",
"knitr","purrr","tm","cba","caret",
"plumber","httr")

安装这些实际上需要大约 1 小时!

It actually takes around 1 hour to install these!

关于如何加快这样的事情的任何建议?(或者如何防止在每次新镜像构建时重新安装?)

Any suggestions into how to speed up such a thing ? (or how to prevent the re-installation at every new image build ?)

旁注

我不会像这样从 dockerfile 安装这些包:

I do not install these packages from the dockerfile like this:

RUN Rscript -e "install.packages('stringr')
...

相反,我创建了一个 R 脚本 Requirements.R 来安装这些包并简单地执行以下操作:

Instead I create an R script Requirements.R which installs these packages and simply do:

RUN Rscript Requirements.R

这些是否不如直接从 Dockerfile 安装包优化?

Is these less optimal than installing the packages directly from the Dockerfile ?

推荐答案

使用 二进制包 就像我们在 Rocker Project 为 R 提供多个 Docker 文件,包括官方的 r-base 文件.

Use binary packages where you can as we often do in the Rocker Project providing multiple Docker files for R, including the official r-base one.

如果你从 Ubuntu 开始,你会得到 Michael 的 PPA3000+ 包;如果您从 Debian 开始,您从发行版中获得的收益会更少,但仍然有很多必不可少的.(有一些努力为 Debian 带来更多的二进制包,但现在什么都没有.)

If you start from Ubuntu, you get Michael's PPAs with over 3000+ packages; if you start from Debian you get fewer from the distro but still many essential ones. (There are some efforts to bring more binary packages to Debian but nothing is up right now.)

最后,Dockerfile 创建当然也是编译时间.您花费一次时间(每个容器创建)并在之后可能多次重复使用.此外,通过使用 Docker Hub,您可以避免花费本地 CPU 周期.

Lastly, Dockerfile creation is of course compile time too. You spend the time once (per container creation) and re-use potentially many time after. Also, by using the Docker Hub you can avoid spending your local cpu cycles.

2020 年 9 月(更新)Ubuntu PPA 现在有超过 4600 个包,用于三个最新的 LTS 版本.仍然强烈,强烈推荐.

Edit in Sep 2020: The (updated) Ubuntu PPA now has over 4600 package for the three most recent LTS releases. Still highly, highly recommended.

这篇关于如何在 docker 中加快 R 包的安装速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆