使用source执行脚本切换目录才有效
source ./chdir.sh
关闭容器脚本
删除镜像 docker rmi $(docker images -q -f dangling=true) 容器如果存在删除容器 if [ $(docker ps -aq --filter name= cicd-demo) ]; then docker rm -f cicd-demo;fi
根据端口清除容器
#!/bin/bash if [ -z "$1" ]; then echo "you must input a port" exit 0 fi PID=$(netstat -nlp | grep ":$1" | awk '{print $7}' | awk -F '[ / ]' '{print $1}') ImageName="myshop" ConatinName="shoptool_contain" # shellcheck disable=SC2181 if [ "${PID}" != "" ]; then echo "process id is:${PID}" docker stop ${ConatinName} # shellcheck disable=SC2181 if [ $? != 0 ]; then echo "停止旧容器失败" exit 2 fi docker rm ${ConatinName} if [ $? != 0 ]; then echo "删除旧容器失败" exit 2 fi docker rmi -f ${ImageName} if [ $? != 0 ]; then echo "删除旧镜像失败" exit 2 fi else echo "process $1 no exit" echo "不存在旧容器" exit 0 fi
解决win下编辑脚本出现的错误