Using containers (Docker/Singularity) in science

Creating your own docker images


Teaching: min
Exercises: 10 min
  • How can I build my own images?

  • Learn how to create Docker images

Creating Docker images

Docker images are created using simple recipe files called Dockerfiles. Let’s create a Dockerfile. Open your favourite editor and type the following text, and save it under the name Dockerfile (no extensions) inside an empty folder.

FROM bids/base_fsl
RUN wget -O /opt/
RUN /bin/bash /opt/ -b -p /opt/conda
ENV PATH="/opt/conda/bin:$PATH"

Open a terminal in the same directory and run the following command:

docker build -t fsl_with_conda .

Don’t forget about the dot at the end! It indicates the directory where Docker will look for a Dockerfile - in our case it’s the current working directory. This should build your image. You can run it like the previous one:

docker run -ti --rm fsl_with_conda


  1. Can you run python inside the container?
  2. What happens if you run the build command again?
  3. Could you modify your Dockerfile to include extra python packages?
  4. When you rebuild your image did you notice something unusual?

Key Points