Adding Dependencies

TensorFlow images don’t include all libraries that you may need. For example, if your project depends on a Python library which isn’t available in the TensorFlow, you need install it. The question is that how to install more system or Python dependencies to TensorFlow container? Apptainer allows you to create a new container and use another container as a base to that container. This can be accomplished by creating a def file, which uses a TensorFlow container as a base container and install the required software in it.


If you want to install a Python library named matplotlib into a GPU TensorFlow container, follow the next steps:

  1. Find the intended TensorFlow container with the appropriate tag. For this example, the tensorflow/tensorflow container is required with the tag latest-gpu.

  2. Create a def file baseContainer.def that uses the TensorFlow container as a base container and install the required software. The def file looks like the following:

    Bootstrap: docker
    From: tensorflow/tensorflow:latest-gpu
    	python -m pip3 install -U matplotlib

    For more information about Apptainer definition file, see Build Recipe.

    You can also use a TensorFlow SIF image a base image for you container. The following def file uses a local SIF image as a base image, and installs matplotlib.

    Bootstrap: localimage
    From: /path/to/localImage.sif
    	python -m pip3 install -U matplotlib
  3. To build your container, you can use the apptainer build command as shown in Building Containers.