Fast bioinformatics containers with Micromamba
From Conda to Docker
Miniconda environments are an easy to use and flexible way of organising dependencies, and to ensure reproducibility as each environment can be shared as a YAML file.
In this short note, we will see how to generate an environment to be used to generate a Docker container.
Generating the environment
We will use mamba to quickly generate a new environment with the tools we need (see Miniconda tutorial).
For this example we will use a set of tools from bioconda. If needed, we can specify the exact version,
or a version range (e. g. samtools>=1.14
).
1
2
mamba env create -n MyEnv -c conda-forge -c bioconda -y \
fastp bwa "seqfu>1.9" "samtools=1.14"
Save the environment as a file
A handy feature of Miniconda is the possibility of saving the current environment to a YAML file.
Adding --no-builds
will skip the build specification from the YAML file.
1
2
3
4
5
6
# Activate the generated environment first
conda activate MyEnv
# Export the environment, removing the first and last line
# that specify the environment name and prefix (path)
conda env export | head -n -1 | tail -n +2 > environment.yaml
Dockerfile
Micromamba is a striped-down version of conda, based on mamba, and is available as a docker image, that we can use to make a Dockerfile.
1
2
3
4
5
6
FROM mambaorg/micromamba:0.19.1
RUN mkdir /home/mambauser/eggnog
COPY --chown=$MAMBA_USER:$MAMBA_USER environment.yaml /tmp/env.yaml
ARG MAMBA_DOCKERFILE_ACTIVATE=1
RUN micromamba install -y --file env.yaml && \
micromamba clean --all --yes
To build the image:
1
docker build -t imagename .
By default, Docker will run as a root (thus requiring sudo). To allow your user to run sudo-less docker commands:
1
2
3
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Singularity
If you push your docker container to a hub, from there you can pull the image as a singularity container. If using Docker Hub, for example:
-
docker login
with your username and password (required once) - Build the image tagging it as
username/imagename:version
- Push the image to the repository with
docker push username/imagename:version
To generate the Singularity image:
1
singularity pull docker://username/imagename:version