<@ULVA73B9P> Attach Podman GPUs arguments to Docke...
# ask-marvin
p
@Marvin Attach Podman GPUs arguments to Docker in order to use Docker with GPUs.
m
To attach GPU support to Docker when running containers, you typically use the NVIDIA Container Toolkit, which allows Docker to recognize and utilize GPUs on the host system. However, if you're discussing Podman, Podman's command line is largely compatible with Docker's and as of my last update, Podman supports GPUs through its
--gpus
flag. Here's how you could theoretically forward
--gpus
arguments from Podman to Docker, although in reality Docker commands directly support GPU access using their own syntax. 1. Using Docker with NVIDIA GPUs (the officially supported way): First, ensure the NVIDIA drivers and the NVIDIA Container Toolkit are installed on your host system. Then you can run Docker containers with GPU access using the
--gpus
flag. For example:
Copy code
sh
   docker run --gpus all nvidia/cuda:10.0-base nvidia-smi
2. Using Podman with GPUs: For Podman, the process is similar as long as your system has the necessary GPU support. You can use the
--gpus
flag much like you would with Docker:
Copy code
sh
   podman run --gpus all <image> <command>
3. Forwarding
--gpus
from Podman to Docker:
If you're scripting or have a special use case where you need to forward the
--gpus
argument from Podman to Docker, you'd essentially be capturing the
--gpus
flag from a Podman command and then crafting a corresponding Docker command. It's a bit unconventional, but here's a simple theoretical example:
Copy code
sh
   #!/bin/bash
   # gpu_forward.sh

   # This script forwards the GPU arguments from Podman to Docker.
   # NOTE: This is a hypothetical example and might not work perfectly in practice.

   # Capture arguments until you encounter the `--gpus` flag
   args=()
   while [[ "$#" -gt 0 ]]; do
     case $1 in
       --gpus) gpu_arg="$1 $2"; shift ;; # Capture the --gpus argument
       *) args+=("$1") ;; # Add other arguments to the array
     esac
     shift
   done

   # Forward the captured GPU argument to Docker
   if [ ! -z "$gpu_arg" ]; then
     docker "${args[@]}" $gpu_arg
   else
     docker "${args[@]}"
   fi
To use this script, you'd call it like so:
Copy code
sh
   ./gpu_forward.sh run --gpus all <image> <command>
Please note that in practice, you shouldn't need to forward arguments from Podman to Docker like this, as you can simply use Docker's native
--gpus
flag to access GPUs within containers.