Containers for HPC
  • Jupyter Notebooks in Containers for HPCs
    • Intro to Docker
    • FACET2 Injector Simulation Docker Image Configuration
Powered by GitBook
On this page
  • Download sample code
  • Build and Run the Docker Container
  • On the VM, Pull and Run the Image:
  1. Jupyter Notebooks in Containers for HPCs

Intro to Docker

This tutorial introduces containers via teaching how to use docker. This part is not designed for HPC but understanding the idea of a container is important.

PreviousJupyter Notebooks in Containers for HPCsNextFACET2 Injector Simulation Docker Image Configuration

Last updated 7 months ago

If you understand docker then skip to .


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:

  1. Ensures Consistency across different environments (e.g., development, testing, production).

  2. Isolates Applications, preventing conflicts and improving security.

  3. Makes Deployment Easy by packaging everything needed to run an app in one container.

  4. 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.

Download sample code

git clone https://github.com/sanjeev-one/Intro-to-Supercomputing-24---Duke-IEEE.git

The dockerfile tells docker how to setup the containner:

```dockerfile
# Use the official Python image with version 3.8
FROM python:3.8-slim

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . .

# Install any dependencies specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Run ml_app.py when the container launches
CMD ["python", "ml_app.py"]

```

Build and Run the Docker Container

Build the Docker Image:

docker build -t ml-app .

Run the Container Locally:

docker run ml-app

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

docker login

Tag and Push the Image: (change username to your docker hub account username)

docker tag ml-app username/ml-app
docker push username/ml-app

On the VM, Pull and Run the Image:

  1. Pull the Docker Image:

    docker pull dukeieee/ml-app

    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.

  2. Run the Docker Container:

    docker run dukeieee/ml-app

    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.

In a local terminal that has the directory with ml_app.py open: (This may need logging into docker with docker login and using a account)

You can follow to connect to a jetstream 2 vm

dockerhub
here
here
Page cover image