Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
快速构建Docker形象_R_Docker_Containers - Fatal编程技术网

快速构建Docker形象

快速构建Docker形象,r,docker,containers,R,Docker,Containers,我计划使用一项服务来接收学生提交的代码,并为下学期我要教的课程评分 对于每个任务(有许多任务),都会运行一个shell脚本来构建Docker映像。我上传了一个zip文件到网站,在所有压缩文件中,有一个: #!/usr/bin/env bash # these lines install R on the virtual machine apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev apt-get install

我计划使用一项服务来接收学生提交的代码,并为下学期我要教的课程评分

对于每个任务(有许多任务),都会运行一个shell脚本来构建Docker映像。我上传了一个zip文件到网站,在所有压缩文件中,有一个:

#!/usr/bin/env bash

# these lines install R on the  virtual machine
apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev
apt-get install -y r-base

# these lines install the packages that is needed both
# 1. the student code 
# 2. the autograding code

# Note that 
# a. devtools is for install_github This is temporary and will be changed once the updates to gradeR have made it to CRAN.
Rscript -e "install.packages('devtools')" 
Rscript -e "library(devtools); install_github('tbrown122387/gradeR')"

# These are packages that many students in the class will use
Rscript -e "install.packages('tidyverse')" 
Rscript -e "install.packages('stringr')" 
但问题是这大约需要20分钟。我如何加快速度?我对Docker容器完全陌生。

使用Docker Hub中的图像,而不是您正在使用的任何图像

第一:

docker pull rocker/tidyverse
然后添加以下行:

FROM rocker/verse

首先,我建议构建一个基本映像,其中包含您认为需要的所有工具和包。没有必要挑剔,因为你只需要做一次。这就是Docker的全部要点——可移植性和重用性

FROM ubuntu:bionic

RUN apt-get update && apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev r-base

RUN Rscript -e "install.packages('tidyverse')" 
RUN Rscript -e "install.packages('stringr')" 
...
构建该图像并将其标记为
分级器:1.0.0
或其他任何内容

然后,在评分时,只需使用
-v,--volume
选项将作业和评分代码装载到
docker run
。您不需要修改容器,就可以访问其中的文件

docker run \
  --rm \
  -it \
  -v /path/to/assignments:/data/assignments \
  -v /path/to/autograder:/data/autograder \
  grader:1.0.0 \
  /bin/bash
如果在某个时候需要添加一些包,可以通过修改原始Dockerfile来重建它,或者通过将其用作下一个映像的基础来扩展它:

FROM grader:1.0.0

RUN apt-get update && apt-get install -y the-package-i-forgot

构建它,标记它。

一个编辑是添加
--无安装建议
以获得安装。这将确保只安装所需的依赖项。我将投票重新打开。此问题不需要调试详细信息,因为没有要调试的内容。这是工作代码。问题是速度太慢了。@Taylor并没有让你的问题更适合回答。在你的问题的当前情况和状态下,只有你才能准确地指出需要花费那么多时间的路线。嗯,根据主机操作系统的不同,这可能弊大于利。Mac和Windows上的卷有着漫长的缓慢历史