|
| 1 | +# Getting Started with Apptainer on Torch |
| 2 | + |
| 3 | +This tutorial walks you through running your first container on the Torch HPC cluster using Apptainer. By the end of this guide, you will be able to pull a container image, run it, and execute commands inside a containerized environment. |
| 4 | + |
| 5 | +## Step 1: Pull a Container Image |
| 6 | + |
| 7 | +Make sure you are on a compute node (via `srun --pty bash`) before proceeding, as running containers on login nodes is not recommended. |
| 8 | + |
| 9 | +Pull a container image from Docker Hub: |
| 10 | + |
| 11 | +```sh |
| 12 | +apptainer pull docker://python:3.10 |
| 13 | +``` |
| 14 | + |
| 15 | +This command downloads a Docker image and converts it into an Apptainer image (`.sif`) that can be run on the cluster. |
| 16 | + |
| 17 | +## Step 2: Run the Container |
| 18 | + |
| 19 | +You can run the container using: |
| 20 | + |
| 21 | +```sh |
| 22 | +apptainer run python_3.10.sif |
| 23 | +``` |
| 24 | + |
| 25 | +This executes the default command defined by the container image. |
| 26 | + |
| 27 | +## Step 3: Execute Commands Inside the Container |
| 28 | + |
| 29 | +To run specific commands inside the container, use: |
| 30 | + |
| 31 | +```sh |
| 32 | +apptainer exec python_3.10.sif python -c "print('Hello from container')" |
| 33 | +``` |
| 34 | + |
| 35 | +This runs a Python command inside the containerized environment. |
| 36 | + |
| 37 | +## Step 4: Run a Simple Scientific Example |
| 38 | + |
| 39 | +Containers are commonly used in research workflows. For example, you can run a simple NumPy computation: |
| 40 | + |
| 41 | +```sh |
| 42 | +apptainer exec python_3.10.sif python -c "import numpy as np; print(np.arange(5))" |
| 43 | +``` |
| 44 | + |
| 45 | +This demonstrates how containerized environments can be used to run scientific Python code without installing dependencies locally. |
| 46 | + |
| 47 | +## Step 5: Explore the Container Environment |
| 48 | + |
| 49 | +Start an interactive shell inside the container: |
| 50 | + |
| 51 | +```sh |
| 52 | +apptainer shell python_3.10.sif |
| 53 | +``` |
| 54 | + |
| 55 | +Once inside, you can run commands as if you were in a separate environment: |
| 56 | + |
| 57 | +```sh |
| 58 | +python |
| 59 | +``` |
| 60 | + |
| 61 | +To exit the container: |
| 62 | + |
| 63 | +```sh |
| 64 | +exit |
| 65 | +``` |
0 commit comments