Using containers (Docker/Singularity) in science

Pulling and running a container


Teaching: 0 min
Exercises: 15 min
  • Pull (download) an image from Docker Hub

  • Run shell inside a container

  • Mount local folders

  • Apply software from the image to analyze local data

Pulling and image

Let’s pull (download) an image: docker pull bids/base_fsl

Where is this image coming from? From Docker Hub.

Getting inside a container

Let’s go inside the container (an instance of an image) and poke around: docker run -ti --rm bids/base_fsl

A Linux shell prompt should appear (independently of your host operating system!). Play around. Can you answer the following questions:

Accessing local files

Before we try to access files from the localhost lets get some example data

  1. Create a folder on your local machine. I went with /d/docker_tutorial
  2. Go to pick a map (for example this one and download it to the example folder.

Let’s mount this folder so it will be accessible from the container when we run it docker run -ti --rm -v D:\docker_tutorial:/data bids/base_fsl


  1. Can you see the downloaded map in /data folder inside the container?
  2. Can you use tools installed in the container on the files in the /data folder? For example fslmaths /data/tfMRI_SOCIAL_TOM-RANDOM_zstat1.nii.gz -kernel gauss 10 /data/smoothed.nii.gz
  3. After getting out of the container can you see the modified files on your host system?

Key Points