Step 1: Create a Dockerfile and add the following to it:
FROM rocker/verse:4.1.0
LABEL org.opencontainers.image.authors="nkhoshnevis@g.harvard.edu"
RUN install2.r --error --skipinstalled --ncpus -1 \
SuperLearner
ENV RENV_VERSION 0.15.1
RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))"
RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')"
# Linux internal commands
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
vim \
zsh \
&& apt-get clean
#
Step 2: Build an image
In the terminal, run:
docker build -t rvers .
Step 3: Create a folder on your host and get the path. Step 4: Run the following code to spin up a Docker container
docker run -it --rm \
-p 8230:8787 \
-e USER=user \
-e PASSWORD=pass \
-v "/path/to/your/folder/on/host:/home/rstudio/Project_A" rvers
Step 5: Go to your browser, open http://localhost:8230/
, and put user
, pass
.
Step 6: It will open an RStudio session. Under the file, click on Open Project and select Project_A folder.
Step 7: Create a new R file, add some content and save.
Step 8: Double-check your host to see if you can see the file with contents.