Docker Community Forums

Share and learn in the Docker community.

Pass arguments to R function within dockerfile

I created the following dockerfile:

FROM rocker/r-base:latest
ARG api_key=my_super_secret_password
RUN R -e "install.packages('remotes')" 
RUN R -e "remotes::install_cran('remoter')" 
EXPOSE 1982 
CMD ["R", "-e remoter::server(port = 1982, password=$api_key)"]

My goal is to get the container to run the R function remoter::server(port = 1982, password=$api_key). Alas, when I try to get this to work I get the following errors:

ignacio@server:/nfs/config/docker/imremoter$ docker-compose up
Recreating imremoter ... done
Attaching to imremoter
imremoter    | ARGUMENT '=' __ignored__
imremoter    |
imremoter    | ARGUMENT '1982,' __ignored__
imremoter    |
imremoter    | ARGUMENT 'password=$api_key)' __ignored__
imremoter    |
imremoter    |
imremoter    | R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
imremoter    | Copyright (C) 2018 The R Foundation for Statistical Computing
imremoter    | Platform: x86_64-pc-linux-gnu (64-bit)
imremoter    |
imremoter    | R is free software and comes with ABSOLUTELY NO WARRANTY.
imremoter    | You are welcome to redistribute it under certain conditions.
imremoter    | Type 'license()' or 'licence()' for distribution details.
imremoter    |
imremoter    |   Natural language support but running in an English locale
imremoter    |
imremoter    | R is a collaborative project with many contributors.
imremoter    | Type 'contributors()' for more information and
imremoter    | 'citation()' on how to cite R or R packages in publications.
imremoter    |
imremoter    | Type 'demo()' for some demos, 'help()' for on-line help, or
imremoter    | 'help.start()' for an HTML browser interface to help.
imremoter    | Type 'q()' to quit R.
imremoter    |
imremoter    | > remoter::server(port
imremoter    | +
imremoter    | + Error: unexpected end of input
imremoter    | Execution halted

How can I fix this?