Apptainer: Difference between revisions

Jump to navigation Jump to search
→‎Example Use Cases: Create an Apptainer container from a Dockerfile
(→‎Example Use Cases: Create an Apptainer container from a Dockerfile)
Line 188: Line 188:


Text to come.
Text to come.
==Creating an Apptainer Container From a Dockerfile==
Unfortunately some instructions for packages only provide a <code>Dockerfile</code> without a container image. A <code>Dockerfile</code> contains the instructions necessary for the Docker software to build that container. Our clusters do not have the Docker software installed. That said, if you've access to a system with both Docker and Apptainer installed, and, sufficient access to Docker (e.g., <code>sudo</code> or root access, or, you are in that system's <code>docker</code> group) and, if needed, Apptainer (e.g., <code>sudo</code> or root access, or, you have <code>--fakeroot</code> access, then you can follow the instructions below to use Docker and then Apptainer to obtain an Apptainer image on that system.
NOTE: Using Docker may fail if you are not in the <code>docker</code> group. Similarly, building some containers may fail with Apptainer without appropriate <code>sudo</code>, root, or <code>--fakeroot</code> permissions. It is your responsibility to ensure you've such access on the system you are running the commands below.
If one only has a Dockerfile and wishes to create an Apptainer image, run the following on a computer with Docker and Apptainer installed (where you've sufficient permissions, etc.):
docker build -f Dockerfile -t your-tag-name
docker save your-tag-name -o your-tarball-name.tar
docker image rm your-tag-name
apptainer build --fakeroot your-sif-name.sif docker-archive://your-tarball-name.tar
rm -f your-tarball-name.tar
where:
* <code>your-tag-name</code> is a name you make up that will identify the container created in Docker
* <code>your-tarball-name.tar</code> is a filename you create that Docker will save the generated content of the container to
* <code>--fakeroot</code> is possibly optional (if so omit such); if <code>sudo</code> is needed instead then omit <code>--fakeroot</code> and prefix the line with <code>sudo</code>
* <code>your-sif-name.sif</code> is the name of the Apptainer SIF file for the Apptainer container
After this is done, the SIF file is an Apptainer container for the <code>Dockerfile</code>. Transfer the SIF to the approprate cluster(s) in order to use such.
'''NOTE:''' It is possible that the Dockerfile pulled in more layers which means you will have to manually delete those additional layers by running:
docker images
followed by runninng <code>docker image rm ID</code> (where ID is the image ID output from the <code>docker images</code> command) in order to free up the disk space associated with those other image layers on the system you are using.


=FAQ=
=FAQ=


Text to come.
Text to come.
cc_staff
156

edits

Navigation menu