Edits history of script submission #383 for ' Run a docker container (docker)'

  • bash
    One script reply has been approved by the moderators
    Ap­pro­ved
    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 hugo697 372 days ago

  • bash
    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 1070 days ago