Quick start on “Creating a new docker container”

As a bioinfomatician, one might get into the situation that requires you to run that software in certain environment again and again, unfortunately, on various computers.

The good news is there’s this thing called “Docker”, a container technology that might allow you to do so easier. If you are a fan of “Singularity”, you already know what I’m talking about here.

Without further ado, here’s what you will need:

  1. You’ll need to install Docker on your computer. Also, get a docker hub account. You’ll need this to deposit your docker image.
  2. Get the source code or the pre-compiled software that you want to run
  3. Create a new working directory to store your Dockerfile (see below)
  4. The most important step, which will determine how complicate your life will be authoring a Dockerfile​ is how you choose your base image.
    • Assuming you are trying to run java application, your best bet for the base image would be this image family java:openjdk-8-jre

Consider the following example (stolen from Broad’s Institute tutorial for FireCloud https://software.broadinstitute.org/firecloud/documentation/article?id=9453)

# Specify the base image -- here we're using one that bundles the OpenJDK version of Java 8 on top of a generic Debian Linux OS
FROM java:openjdk-8-jre

#Set the working directory to be used when the docker gets run

# Do a few updates of the base system and install R (via the r-base package)
RUN apt-get update && \
        apt-get upgrade -y && \
        apt-get install -y r-base

# Install the ggplot2 library and a few other dependencies we want to have available
RUN echo "r <- getOption('repos'); r['CRAN'] <- 'http://cran.us.r-project.org'; options(repos = r);" > ~/.Rprofile
RUN Rscript -e "install.packages('reshape')"
RUN Rscript -e "install.packages('gplots')"
RUN Rscript -e "install.packages('ggplot2')"

# Add the Picard jar file (assumes the jar file is in the same directory as the Dockerfile, but you could provide a path to another location)
COPY picard.jar /usr/picard.jar

To build the image

Now to build this Dockerfile containing in the current directory

​docker build -t <username>/<repo>:<tag> .

Running your new app

​docker run -it <username>/<repo>:<tag>

You should get a prompt like this one root@ca9af9b92f3d:/usr#

Once you are in your new Docker container running environment, consider using the software as if you have installed it on your computer.

That’s it!

Push your container to the repository

docker push <username>/<repo>:<tag>


Author: hypotheses

My name is Bhoom Suktitipat. I am currently an assistant professor at Faculty of Medicine Siriraj Hospital, Mahidol University.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.