Created
April 24, 2020 16:55
-
-
Save davidtedfordholt/06b5ffa6862f59e98dac0a6021a24584 to your computer and use it in GitHub Desktop.
Simple Dockerfile for R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Base image | |
FROM rocker/r-base | |
# Copy R scripts to container | |
COPY / ./ | |
# Execute when container is BUILT: | |
# sudo docker build -t example_container . | |
RUN Rscript setup.R | |
# Execute when container is RUN: | |
# sudo docker run --rm example_container | |
CMD Rscript run.R |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("I built a container!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("I am building a container.") |
My first swag was just
FROM rocker/r-base
RUN R -e 'print("I am building a container.")'
CMD R -e 'print("I built a container!")
but that seems a bit hard to extrapolate from. :)
Or, for my very favorite @jtbaker:
echo -e "FROM rocker/r-base\n COPY / ./\n CMD Rscript run.R" >> Dockerfile && echo "print('I love you, Jason')" >> run.R && docker build -t ex . && docker run --rm ex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Dockerfile will execute
setup.R
during the building of the image andrun.R
during the running of the container.Each time you run the container, it will start from a state of having already executed everything above the
CMD
line. This means that, if you had defined objects or variables in the container's environment in earlier lines, they are available in the container's environment. This includes system variables and files created.Remember, however, that the R environment of the script in the
CMD
line is not the same as the R environment of the script in theRUN
line.