image="${1:-alpine:latest}"
port_host="${2:-8080}"
port_container="${3:-8080}"
name="${4:-my_container}"
gpu="${5:-true}"
# if gpu is true, then add the gpu flag
if [ "$gpu" = true ] ; then
gpu_flag="--gpus all"
else
gpu_flag=""
fi
# Stop the container if it is running
docker stop "$name" 2>/dev/null || true
# Run the container
docker run -d \
--rm \
--name "$name" \
-p "$port_host:$port_container" \
$gpu_flag \
"$image"
Submitted by yassinsiouda74165 642 days ago