|
| 1 | +# Docker |
| 2 | + |
| 3 | +## Navigating Docker Desktop/CLI |
| 4 | + |
| 5 | +- Install Docker on [Mac](https://docs.docker.com/desktop/setup/install/mac-install/), [Windows](https://docs.docker.com/desktop/setup/install/windows-install/), or [Linux](https://docs.docker.com/desktop/setup/install/linux/). |
| 6 | + |
| 7 | +Via Docker Desktop GUI, |
| 8 | +- Search for [sbryngelson/mfc](https://hub.docker.com/r/sbryngelson/mfc) repository where all MFC images are stored then pull a release tag (e.g. `lastest-cpu`). |
| 9 | + |
| 10 | + Read through **Tag Details** below to distinguish between them. Docker Desktop's left sidebar has two key tabs: **Images** stores your program copies, while **Containers** shows instances of those images. You can launch multiple containers from a single image. |
| 11 | + |
| 12 | +- Start a container by clicking the Run button in the Images tab. |
| 13 | + |
| 14 | + Use the *Exec* section to interact with MFC directly via terminal, the *Files* section to transfer files between your device and container, and the *Stats* section displays resource usage of it. |
| 15 | + |
| 16 | +Or via Docker CLI, |
| 17 | + |
| 18 | +- Pull from [sbryngelson/mfc](https://hub.docker.com/r/sbryngelson/mfc) repository and run the latest MFC container. |
| 19 | + |
| 20 | +```bash |
| 21 | +docker run -it --rm --entrypoint bash sbryngelson/mfc:latest-cpu |
| 22 | +``` |
| 23 | + |
| 24 | +## Running Containers |
| 25 | + |
| 26 | +Start a CPU container |
| 27 | +```bash |
| 28 | +docker run -it --rm --entrypoint bash sbryngelson/mfc:latest-cpu |
| 29 | +``` |
| 30 | +Start a GPU container |
| 31 | +```bash |
| 32 | +docker run -it --rm --entrypoint bash --gpus all sbryngelson/mfc:latest-gpu |
| 33 | +``` |
| 34 | +**Note:** `--gpus all` exposes the container to available GPUs, and only Nvidia GPUs are currently supported. Make sure your device CUDA version is at least 12.3 to avoid backward compatibility issues. |
| 35 | + |
| 36 | +*⚠️ Append the `--debug` option to the `./mfc.sh` command inside the container with **Apple Silicon** (ARM-based Architecture) to bypass any potential errors or run `./mfc.sh clean && ./mfc.sh build` if needed.* |
| 37 | +<br> |
| 38 | +<br> |
| 39 | + |
| 40 | +**Mounting Directory:** |
| 41 | + |
| 42 | +Mount a directory to `mnt` inside the container to easily transfer files between the host and the container, e.g. `cp -r <source> /mnt/`. |
| 43 | +```bash |
| 44 | +docker run -it --rm --entrypoint bash -v "$PWD":/mnt sbryngelson/mfc:latest-cpu |
| 45 | +``` |
| 46 | +<br> |
| 47 | + |
| 48 | +**Shared Memory:** |
| 49 | + |
| 50 | +Increase the shared memory size to prevent MPI memory binding errors which may fail some tests and cases. Otherwie, you can disable MPI inside the container `--no-mpi`. |
| 51 | +```bash |
| 52 | +docker run -it --rm --entrypoint bash --shm-size=<e.g. 4gb> sbryngelson/mfc:latest-cpu |
| 53 | +``` |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +### **For Portability,** |
| 59 | + |
| 60 | +On the source machine, |
| 61 | +- Pull and save the image |
| 62 | +```bash |
| 63 | +docker pull sbryngelson/mfc:latest-cpu |
| 64 | +docker save -o mfc:latest-cpu.tar sbryngelson/mfc:latest-cpu |
| 65 | +``` |
| 66 | +On the target machine, |
| 67 | +- Load and run the image |
| 68 | +```bash |
| 69 | +docker load -i mfc:latest-cpu.tar |
| 70 | +docker run -it --rm mfc:latest-cpu |
| 71 | +``` |
| 72 | + |
| 73 | +<br> |
| 74 | + |
| 75 | +## HPC Cluster Usage (Apptainer/Singularity) |
| 76 | + |
| 77 | +### **Interactive Shell** |
| 78 | +```bash |
| 79 | +apptainer exec --fakeroot --writable-tmpfs --bind "$PWD":/mnt docker://sbryngelson/mfc:latest-gpu bash -c "cd /opt/MFC && bash" |
| 80 | +``` |
| 81 | +or |
| 82 | +```bash |
| 83 | +apptainer shell --fakeroot --writable-tmpfs --bind "$PWD":/mnt docker://sbryngelson/mfc:latest-gpu |
| 84 | +Apptainer>cd /opt/MFC |
| 85 | +``` |
| 86 | + |
| 87 | +### **For Portability,** |
| 88 | +On the source machine, |
| 89 | +- Pull and translate the image into `.sif` format |
| 90 | +```bash |
| 91 | +apptainer build mfc:latest-gpu.sif docker://sbryngelson/mfc:latest-gpu |
| 92 | +``` |
| 93 | +On the target machine, |
| 94 | +- Load and start an interactive shell |
| 95 | +```bash |
| 96 | +apptainer shell --fakeroot --writable-tmpfs --bind "$PWD":/mnt mfc:latest-gpu.sif |
| 97 | +``` |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +### Slurm Job |
| 102 | +```bash |
| 103 | +#!/bin/bash |
| 104 | +#SBATCH --job-name=mfc-sim |
| 105 | +#SBATCH --nodes=2 |
| 106 | +#SBATCH --ntasks-per-node=12 |
| 107 | +#SBATCH --time=06:00:00 |
| 108 | +#SBATCH --partition= |
| 109 | +#SBATCH --output=mfc-sim-%j.out |
| 110 | +#SBATCH --error=mfc-sim-%j.err |
| 111 | + |
| 112 | +# Load required modules |
| 113 | +module load apptainer |
| 114 | + |
| 115 | +cd $SLURM_SUBMIT_DIR |
| 116 | + |
| 117 | +# Define container image |
| 118 | +CONTAINER="mfc:latest-gpu.sif" |
| 119 | + |
| 120 | +apptainer exec --fakeroot --writable-tmpfs \ |
| 121 | +--bind "$PWD":/mnt \ |
| 122 | + $CONTAINER \ |
| 123 | + bash -c "cd /opt/MFC && ./mfc.sh run sim/case.py -c <computer>" |
| 124 | +``` |
| 125 | +Where |
| 126 | + |
| 127 | +`/sim` directory contains all simulation files including case setup (`case.py`). |
| 128 | + |
| 129 | +`--fakeroot --writable-tmpfs` are critical to: |
| 130 | +- Enable root-like permissions inside the container without actual root access |
| 131 | +- Allow temporary write access to the container filesystem |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +## Tag Details |
| 136 | +### Base Images |
| 137 | +- CPU images (v4.3.0-latest releases) are built on **Ubuntu 22.04**. |
| 138 | +- GPU images (v4.3.0-latest releases) are built on **NVHPC SDK 23.11 (CUDA 12.3) & Ubuntu 22.04**. |
| 139 | + |
| 140 | +### Tag Structure |
| 141 | +- **`vx.x.x`** - Official MFC release versions (recommended: use `latest` release) |
| 142 | +- **`cpu/gpu`** - Build configurations for CPU or GPU acceleration. |
| 143 | +- **`ubuntu-xx.xx`** - Base Ubuntu version (standard = `amd64`, `-arm` = `arm64`) |
| 144 | + |
| 145 | +### Available Tags |
| 146 | +``` |
| 147 | +mfc:latest-xxx # Latest version (amd64 & arm64) |
| 148 | +mfc:vx.x.x-cpu # CPU version (amd64 & arm64) |
| 149 | +mfc:vx.x.x-gpu # GPU version (amd64 & arm64) |
| 150 | +mfc:vx.x.x-xxx-ubuntu-xx.xx # amd64 natively-supported version |
| 151 | +mfc:vx.x.x-xxx-ubuntu-xx.xx-arm # arm64 natively-supported version |
| 152 | +``` |
| 153 | +### **Architecture Support** |
| 154 | +You can specify the desired architecture with `--platform <os>/<arch>` - either `linux/amd64` or `linux/arm64`. If not sure, Docker automatically selects the available image compatible with your system architecture. If native support isn't available, QEMU emulation is enabled for the following architectures albeit with degraded performance. |
| 155 | +``` |
| 156 | +linux/amd64 |
| 157 | +linux/amd64/v2 |
| 158 | +linux/amd64/v3 |
| 159 | +linux/arm64 |
| 160 | +linux/riscv64 |
| 161 | +linux/ppc64le |
| 162 | +linux/s390x |
| 163 | +linux/386 |
| 164 | +linux/mips64le |
| 165 | +linux/mips64 |
| 166 | +linux/loong64 |
| 167 | +linux/arm/v7 |
| 168 | +linux/arm/v6 |
| 169 | +``` |
| 170 | + |
| 171 | + |
| 172 | +<br> |
| 173 | +<br> |
0 commit comments