dockerapptainer

Equivalent of "context" in docker build for apptainer build?


I am adapting some Python code that uses Docker to use Apptainer instead, as I only have access to the latter on the HPC system where I am working. The code generates commands with the following form:

docker build --build-arg PYTHON_VERSION={version} {extra} -t {IMAGE_NAME} -f {dockerfile} {CONTAINER_MAIN.parent}

where {version}, {extra}, {IMAGE_NAME}, {dockerfile}, and {CONTAINER_MAIN.parent} are set elsewhere in the code. {extra} is either empty, or a string that begins with "--build-arg".

I want to make a similar command with apptainer.

So far, I've figured out the following:

I can't figure out what the equivalent of that last argument is in apptainer. How do I give apptainer build a context where it can find files?


Solution

  • There is a --bind flag which you could use. As in the docs, you need to make sure the mount point exists in the container, for example:

    Bootstrap: docker
    From: docker.io/library/debian:stable
    
    %setup
        mkdir -p $APPTAINER_ROOTFS/mnt/bind
    
    %post
        # use files from host system here
    

    Then run apptainer build --bind CONTAINER_MAIN.parent:/mnt/bind IMAGE_NAME DEFINITION_FILE