Particularly for courses that involve running example code, it’s highly recommended that you use a Docker image for development to maintain software version consistency across course developers.
If your course doesn’t require any additional packages to run, then you do not need to set up Docker locally but this Docker image: jhudsl/base_ottr will run and re-render all of your changes as you add them.
We advise you use the
jhudsl/base_ottr:main tagged image as opposed to the
main is what is ready for use, while the
latest may be under development. All GitHub actions by default use the
If you are new to Docker, you may find it helpful to read this introduction to Docker.
If your Docker desktop is running, you should see a Docker whale in your tool bar. On Macs, this will be on the bar on the top of your screen; in Windows, on the bottom right.
A Docker image is similar to a virtual machine - it contains preinstalled software in a preconfigured environment. Docker images can be downloaded from DockerHub, or you can create your own.
We have created the
base_ottr:main image as a starting point; you can download it from
jhudsl/base_ottr:main on DockerHub using the docker pull command we have below. To pull the docker image associated with this template, you can run this command below in your command line. This may take a while.
docker pull jhudsl/base_ottr:main
This pulls the base_ottr:main image from Docker Hub and copies it to your computer. It will be placed in your local collection of Docker images, managed by Docker (not in your pwd). If you get an error, it may be because you forgot to have your Docker desktop running… see above.
To use the Docker image associated with the course template, first navigate to the the top of this GitHub repository. Now you can start up the Docker container using the command below.
This runs your local copy of the base_ottr:main image (which you downloaded from DockerHub). The option
-v $PWD:/home/rstudio mounts pwd (this repo) and makes it available at
/home/rstudio within the container. Replace all of
<CHOOSE_PASSWORD> (including the
>) with a password of your choosing.
On a Mac:
docker run -it -v $PWD:/home/rstudio -e PASSWORD=<CHOOSE_PASSWORD> -p 8787:8787 jhudsl/base_ottr:main
On a Windows:
docker run -it -v %CD%:/home/rstudio -e PASSWORD=<CHOOSE_PASSWORD> -p 8787:8787 jhudsl/base_ottr:main
Do not close this window, but you can minimize it. Open up a new command line window and run the command:
docker ps, you should see a container is up and running!
Couple other handy Docker commands:
docker psto obtain the docker container ID. Then you can use that ID to run
docker stop <CONTAINER_ID>.
docker image lsto see all your current images. Then you can run either
docker image rm <IMAGE_ID>.
For more info on how to use Docker, they have very extensive documentation here.
In a web browser navigate to the following to get to an RStudio that is run from your Docker container.
To log in, you’ll need to use
rstudio as the username and whatever password you put for
<CHOOSE_PASSWORD> in the above command.
Should you find that your course needs additional packages beyond what’s included in the template, you should probably start a new Docker image and you’ll need to do these steps to get this going:
There’s a library of other ottr-ready docker images that you can see here. If you would like to contribute your own customized docker image that works with OTTR, please file a pull request!
To make sure that your new Docker image is being used for rendering in the GitHub actions, you need to change the
rendering-docker-image: from the default of
jhudsl/base_ottr:main and replace it with your docker image tag.
Then start a new branch so that you can submit a new pull request with your changes.
Now, when you file a pull request, the Dockerfile build for your docker image will be tested automatically by the GitHub actions if
docker-test is set to
yes. The default is
Read this chapter for instructions on how to modify Docker images
You will probably want to create your Docker image by using the
jhudsl/base_ottr:main as your base – this means that all the packages that are in our
jhudsl/base_ottr:main image will be included in the Docker image you build.
You can take a look at this Dockerfile template we’ve set up here (note that the commands would need to be uncommented and real package names put in place of
This section gives you the basics on what it looks like to add new packages to your new Docker image.
For R packages installed from CRAN, you can add to the running vector list of R packages.
To add an R package from Bioconductor, you can follow this kind of format:
RUN Rscript -e "options(warn = 2); BiocManager::install( \ c('limma', \ 'newpackagename')
To add a Python package, you will need to add pip3 to install Python packages using this format:
RUN pip3 install \ "somepackage==0.1.0"
Read this chapter for instructions on how to modify Docker images
When you’ve added a package to the Dockerfile, you may want to check that it builds successfully before it’s added to your repository. You can include changes to your Dockerfile in a pull request which will trigger an automatic testing of building it.
Read this chapter for more tips on how to modify Docker images
If you prefer to test it locally, then you can follow these steps.
First create a GITHUB token file by making a token and copying a pasting it into a plain text file named
docker/git_token.txt. (Make sure you do not push this to github and possibly delete it after testing your docker image build!)
Then you’ll need to rebuild the Docker image using this command after you move into the
docker directory) (But replace the
<TAG_FOR_COURSE> with the tag for your new image including dropping the
docker build -f Dockerfile . -t <TAG_FOR_COURSE>
If it fails, often the issue is a missing dependency. Take a look at the error messages and see if you can determine the issue with some Googling. Also be sure that all your directories and files are named correctly.
Once it builds successfully, run the above command with the new name for your docker image make sure that the tag does not have upper case characters):
docker build -f Dockerfile . -t jhudsl/<TAG_FOR_COURSE>
For any changes you make to your Docker image to take effect in your repository’s github actions and workflows, you must push your updated docker image to Dockerhub. There are two different ways you can push your Docker image.
Locally, you can push your updated image to Dockerhub using (make sure that the tag does not have upper case characters):
docker push jhudsl/<TAG_FOR_COURSE>
You can use GitHub actions to do this by going to your course’s GitHub repository, go to
Actions and then to
Test build of Dockerfile.
run workflow type in
Push to Dockerhub?.
Run. If your Dockerfile builds an image successfully it will automatically be pushed to Dockerhub.
For your personalized docker image, you can store the Dockerfile anywhere. In order for OTTR/GitHub actions to use it, it must be pushed to Dockerhub.
It may be easiest to store it in the OTTR-made repository you are working from.
In whichever repository you choose to store your Dockerfile, its recommended you use a GitHub action to automatically test it when you make changes. You can use our Docker handling GitHub action here as a starting point.
You will need to modify this GHA for your own purposes:
If you do choose to use the action manually, then you can use this by going to
Actions, clicking on
Build Docker Image >
run workflow and write in:
directory- Which your Dockerfile is located in this repository
tag- Optionally, what tag you wish the built docker image to have
Push to Dockerhub?TRUE or FALSE whether you wish this docker image to be pushed to Dockerhub.
For more guidance on how to personalize Docker images, we recommend joining the Google Group and asking questions on there. Or file a GitHub issue on the relevant repository.