mirror of
https://github.com/DictXiong/dotfiles.git
synced 2024-11-28 08:37:01 +08:00
Dict Xiong
c354f980bb
* piv logi fix * dogo: $DFS * snasp; doll: $2 for the name * DFS_UPDATE_CHANNEL? * git-branches * ci: git-branches Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
26 lines
676 B
Bash
Executable File
26 lines
676 B
Bash
Executable File
#!/bin/bash
|
|
|
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
|
source "$THIS_DIR/../tools/common.sh"
|
|
|
|
DOCKER_FORMAT="{{.ID}} {{.Repository}}:{{.Tag}}"
|
|
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
|
|
fmt_info "usage: $0 <image> or -[0-9]*"
|
|
exit
|
|
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
|
|
LAST="${1:1}"
|
|
# the last nth image
|
|
IMAGE_META=($($SUDO docker image ls --format "$DOCKER_FORMAT" | head -n ${LAST:-1} | tail -n 1))
|
|
IMAGE=${IMAGE_META[0]}
|
|
else
|
|
IMAGE_META="$1"
|
|
IMAGE="$1"
|
|
fi
|
|
|
|
if [[ -z "$IMAGE" ]]; then
|
|
fmt_fatal "image not found"
|
|
else
|
|
echo "--> ${IMAGE_META[@]}"
|
|
$SUDO docker run ${2:+"--name"} $2 -itd $IMAGE sh
|
|
fi
|