Skip to content
rsdmse edited this page Jul 4, 2020 · 8 revisions

Tips for Building Docker Images

Choose base image (FROM)

Label yourself as maintainer (LABEL)

LABEL maintainer=<user>@virginia.edu

Clean up after installation

The installation command and clean up command must be in the same RUN statement.

apt-get (Debian/Ubuntu)

RUN apt-get update && apt-get install -y --no-install-recommends \
        ... && \
    rm -rf /var/lib/apt/lists/*
  • Flag -y is needed
  • Use --no-install-recommends to avoid installing unnecessary packages
  • Line breaks are optional

yum (RHEL/CentOS)

RUN yum -y install ... && \
    yum -y clean all && rm -rf /var/cache/yum

apk (Alpine)

RUN apk add --no-cache ...

No separate clean up is needed.

conda (Anaconda/Miniconda)

RUN conda install ... && \
    conda clean --all

pip

RUN pip install --no-cache-dir ...

Reduce the number of RUN statements

But it is not necessary to concatenate everything into one RUN command.

  • Example: Hydrator has one for apt-get and another for the software.

Add environment variables (ENV)

  • Add PATH, LD_LIBRARY_PATH, etc. for user's convenience.
  • Set LC_ALL C (or some other locale).

Set default run command (ENTRYPOINT)

This is the command that will be executed upon singularity run <app>_<tag>.sif or equivalently ./<app>_<tag>.sif.