简体   繁体   English

如何从 Docker 容器中的一个脚本运行多个 R 脚本

[英]How to run multiple R scripts from one script in a Docker Container

I've got a script called initiate.R which runs two other scripts, like so:我有一个名为initial.R 的脚本,它运行另外两个脚本,如下所示:

source("Step1_databaseConnection.R")
source("Step2_buildingDateInfoAndMainFlowInfo.R")

In my dockerfile I have defined the following:在我的 dockerfile 中,我定义了以下内容:

COPY Step1_databaseConnection.R  /home/project/Step1_databaseConnection.R

COPY Step2_buildingDateInfoAndMainFlowInfo.R  /home/project/Step2_buildingDateInfoAndMainFlowInfo.R

COPY initiate.R  /home/project/initiate.R

CMD ["/usr/local/bin/Rscript", "/home/project/initiate.R"]

However, I get the following error when running the task on AWS: cannot open file 'Step1_databaseConnection.R': No such file or directory但是,在 AWS 上运行任务时出现以下错误:无法打开文件“Step1_databaseConnection.R”:没有这样的文件或目录

When I change my dockerfile to run the two scripts separately it works.当我更改我的 dockerfile 以分别运行这两个脚本时,它可以工作。 Here is the code that works:这是有效的代码:

COPY Step1_databaseConnection.R  /home/project/Step1_databaseConnection.R

COPY Step2_buildingDateInfoAndMainFlowInfo.R  /home/project/Step2_buildingDateInfoAndMainFlowInfo.R

COPY initiate.R  /home/project/initiate.R

CMD ["/usr/local/bin/Rscript", "/home/project/Step1_databaseConnection.R"]

CMD ["/usr/local/bin/Rscript", "/home/project/Step2_buildingDateInfoAndMainFlowInfo.R"]

Any ideas?有任何想法吗? Many thanks非常感谢

In your second try with executing the scripts by hand, you are using absolute paths.在您第二次尝试手动执行脚本时,您使用的是绝对路径。 However, the first try starts the script with the current working directory of docker es working directory of R.但是,第一次尝试使用当前工作目录 docker es 工作目录 R 启动脚本。 This is not the file location.这不是文件位置。 Therefore you have first move to this location with WORKDIR filepath .因此,您首先要使用WORKDIR filepath移动到该位置。 afterthet you can execute the script as expected.之后,您可以按预期执行脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM