Skip to content
Brian M. Schilder edited this page Aug 18, 2021 · 6 revisions

Generate a Docker image with R and Rstudio installed.

From almurphy/scfdev

Alan Murphy created a Docker container that has RStudio, Bioconductor and the R package scFlow installed. Additionally, this container is optimised to enable much master installation of R packages (~8x faster than default).

Note that the OS within this Docker container is Linux (even if you are running it on a Mac).

  1. Install Docker Desktop 

  2. Within Docker Desktop, click the Settings (gear icon) in the upper right, and go to Resources -> Advanced. Raise all the limits to the max (or whatever you like). This prevents Docker from underutilising your computer’s resources. 

  3. Within Docker Desktop, make sure you’re not running any other docker containers that are taking up resources unnecessarily (under the Containers/Apps section).

  4. In command line, create a Docker image using from Alan Murphy's Dockerhub, called scfdev. Make sure to modify the paths that you want to mount to the docker image using the -v flags (syntax: <local_path>:<path_within_container>). This is important to do at this step, because Docker does not have access to any folder/files that you do not explicitly give it access it, and this cannot be changed after creating the Docker image.

docker run \ 
        -e PASSWORD=scflow \
        -p 8787:8787 \
        -v ~/Desktop:/Desktop -v /Volumes:/Volumes \
        almurphy/scfdev
  1. Access the image via a web browser using the URL: http://localhost:8787/ 

  2. Log into RStudio within the browser (username: rstudio, password: scflow). You can now modify the docker image (e.g. installing new packages) and these changes will be saved even after exiting.

From bioconductor

Bioconductor also distributes a similar Docker container (albeit without scFlow and not optimised for fast R package installation).

docker run \
     -e PASSWORD=bioc \
     -p 8787:8787 \
     -v ~/Desktop:/Desktop -v /Volumes:/Volumes \
     bioconductor/bioconductor_docker:devel

Note that the RStudio password here has been set to bioc .

Copying files into root

You may notice that you can't edit root files within the Docker. This is problematic when trying to install packages like MAGMA.

You can resolve this by using the docker cp command (replace my_container with the name of your Docker container):

docker cp ~/Downloads/magma_v1.09a/magma my_container:/bin/magma
# Make sure you give yourself execution permissions when you're using it within the Docker container
docker exec -t -i upbeat_kowalevski chmod +x /bin/magma 

If you get the error cannot execute binary file: Exec format error when trying to run the executable, this probably indicates you added the executable for the wrong OS platform. Note that the OS within your Docker image can be different from the OS your computer runs on.

Setting permissions

Sometimes you'll need root permissions to modify certain files or run certain commands. You'll need to do this outside the docker container (in your computer's Terminal/command line).

First find the randomly assigned name of your Docker image (e.g. "upbeat_kowalevski") in the Docker Desktop application. Then, in the command line, you can change file permissions like so:

docker exec -t -i <docker_image_name> chmod chmod +x <path/to/file>

You can also change permissions to many files/folders at once using the following command:

docker exec -t -i <docker_image_name> chmod -R u=rwx,go=rx <path/to/folder>

Setting token access

When setting up a new Docker env, you'll have to set up a new  .Renviron file.

Step 1.

You only need to do this once. After that, you can just copy and paste the contents of the .Renviron file outside of your container into the .Renviron file inside your container.

# Takes you to GitHub website. Create a token and then copy it
usethis::create_github_token()

Step 2.

Now modify the .Renviron file within your container:

# Opens your .Renviron file. Edit it to include "GITHUB_PAT=<token>" in a new line (no quotes).
usethis::edit_r_environ()
Clone this wiki locally