Featured image of post Docker Images for R and Py

Docker Images for R and Py

To make new docker images for R and Python interactively and without Dockerfile.

I am trying to build docker images with common tools for single-cell and spatial transcriptomics data analysis. The common way to build a new docker image is to use the Dockerfile, where we can define instructions and commands. For example here is one for R:

FROM r-base

## create directories
#RUN mkdir -p /01_data
#RUN mkdir -p /02_code
#RUN mkdir -p /03_output

## copy files
COPY install_packages.R install_packages.R

## install R-packages
RUN Rscript install_packages.R

The problem is that many R packages have dependencies external to R, for example GSL, GDAL, JAGS and so on and we don’t know beforehand and difficult to define in the Dockerfile. To make a new image there is also a way to do it interactively using docker run -it [base image] bash which will bring us to the docker command line (like a system command line), and we can install system dependencies and further R/Python packages from >R or >python.

The good thing is that in R there will be indications what is needed:


So just need to q() and go back to the command line and apt-get install

After we have installed all packages we can type docker ps in another terminal to see the running containers, and to make new image by typing docker commit [container id] image_name:tag

Then we can see the new image in docker images, which we can save and load in another system.

tested on my Mac

Other docker commands:

  • docker push # to upload to dockerhub
  • newgrp docker # after adding a user to the docker group
comments powered by Disqus
CC-BY-NC 4.0
Built with Hugo Theme Stack