Containers for HPC
How to package local code in a container and run it in the cloud
Intro to Docker
Docker is a tool that packages applications and their dependencies into containers, ensuring they run the same way on any system. It's useful because it:
Ensures Consistency across different environments (e.g., development, testing, production).
Isolates Applications, preventing conflicts and improving security.
Makes Deployment Easy by packaging everything needed to run an app in one container.
Increases Efficiency since containers are lightweight and use less resources compared to traditional virtual machines.
In short, Docker simplifies running and deploying applications by making them portable and consistent.
Following requires docker downloaded / docker account. You can skip these steps if you dont have them.
Download sample code
The dockerfile tells docker how to setup the container:
Build and Run the Docker Container
Build the Docker Image:
Run the Container Locally:
This will print the model's accuracy and the prediction for the sample flower measurements in your terminal.
Push to Docker Hub and Deploy on a VM - skip if doing workshop
Log In to Docker Hub: needs https://hub.docker.com/account
Tag and Push the Image: (change username to your docker hub account username)
On the VM, Pull and Run the Image:
You can follow Jetstream 2 tutorial to connect to a jetstream 2 vm
Pull the Docker Image:
This command downloads the Docker image
dukeieee/ml-app
from Docker Hub to your local system or VM. The image contains the Python ML app and its required dependencies.Run the Docker Container:
This command starts a container using the downloaded image. The app will train a machine learning model on the iris dataset and print the model's accuracy and predictions directly to your terminal.
This approach ensures that the app runs with all necessary dependencies, regardless of the environment, providing a consistent and reproducible setup.
HPC Specific Variants
Apptainer
Both Apptainer and Docker are containerization tools, but they have different primary use cases and features:
Apptainer:
Formerly known as Singularity, it's designed for high-performance computing (HPC) environments.
Focuses on user-level container management, which does not require root privileges.
Highly compatible with HPC batch systems and allows seamless integration into shared file systems.
Emphasizes security, enabling users to securely run containers without additional system privileges.
Running container on TAMU Faster
Authorized ACCESS users can log in using the Web Portal:
On a login node:
On a compute node:
Example on Grace, batch job
Create a file named singularity_pull.sh
:
On a login node,
Interact with container
When a container image file is in place at HPRC, it can be used to control your environment for doing computation tasks.
Shell
The shell command allows you to spawn a new shell within your container and interact with it one command at a time. Don't forget to exit
when you're done.
Example:
Executing commands
The exec command allows you to execute a custom command within a container by specifying the image file and the command.
Example program installed inside image:
Example executable file myscript.sh
:
starts with
#!/usr/bin/env bash
has the executable permission set by
chmod u+x myscript.sh
is located in the current directory
Running a container
Last updated