简体   繁体   中英

How to get Rscript to run through docker?

I am trying to get my Rscript to run through a list of data sets on docker. I have gotten the dockerfile set up correctly and it runs fine, the docker image builds fine, but everytime it tries to run through the Rscript, I get this error:

/app/model-1.r: line 24: syntax error near unexpected token `mosaic'
/app/model-1.r: line 24: `library(mosaic)'

My image is based on r-ver in the dockerfile, which also installs all the necessary packages, and I have a command to run the script:

FROM rocker/r-ver:4.0.0

RUN R -e "install.packages('mosaic', repos = 'http://cran.us.r-project.org')"
COPY /model-1.r .
CMD R -e "source('/model-1.r')"

and I've tried adding this command to the Rscript document itself:

#!/usr/bin/env Rscript

library(mosaic)

but nothing has worked. Is there something glaring that I am missing here?

This is the 'run' command that I am using in the terminal:

docker run \
     -v $(pwd)/synthetic_data:/data:ro \
     -v $(pwd)/output:/output:rw \
     -v $(pwd)/scratch:/scratch:rw \
     awesome-model:v1 bash /app/model-1.r

Thank you very much

In this command:

docker run \
     -v $(pwd)/synthetic_data:/data:ro \
     -v $(pwd)/output:/output:rw \
     -v $(pwd)/scratch:/scratch:rw \
     awesome-model:v1 bash /app/model-1.r

The last arguments, bash /app/model-1.r , tell Docker to ignore the CMD specified by the Dockerfile and interpret /app/model-1.r as a Bash script. You probably want to replace bash with Rscript .

I figured it out--I needed to run a separate text file as the command so that my terminal knew that it was reading an Rscript.

#!/usr/bin/env Rscript

Rscript /app/model-1.R

Without the Rscript command, I'm pretty sure it was expecting bash or something like that. So my new command is:

docker run \
     -v $(pwd)/synthetic_data:/data:ro \
     -v $(pwd)/output:/output:rw \
     -v $(pwd)/scratch:/scratch:rw \
     awesome-model:v1 bash /app/command.txt

where command.txt is just a text file containing the above lines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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