docker启动脚本

1.镜像如果存在,停止并删除,pull下来新的,运行。

#!/bin/bash

str=`docker ps |grep 'registry.cn-shenzhen.aliyuncs.com/xxx/unlimited-service-config' |awk '{print $1}'`

if [ $str ] ; then

    echo "stop delete  pull images"

    docker ps -a|grep  registry.cn-shenzhen.aliyuncs.com/xxx/unlimited-service-config |awk '{print $1}'|xargs docker stop |xargs docker rm

    docker images |grep 'registry.cn-shenzhen.aliyuncs.com/xxx/unlimited-service-config' |awk '{print $3}'|xargs docker rmi

    docker login --username=xxx --password=xxx registry.cn-shenzhen.aliyuncs.com

    docker pull registry.cn-shenzhen.aliyuncs.com/xxx/unlimited-service-config

else

    echo "delete pull iamges"

    docker images |grep 'registry.cn-shenzhen.aliyuncs.com/xxxx/unlimited-service-config' |awk '{print $3}'|xargs docker rmi

    docker login --username=xxx --password=xxxx  registry.cn-shenzhen.aliyuncs.com

    docker pull registry.cn-shenzhen.aliyuncs.com/xxxx/unlimited-service-config

fi

#run

sudo  docker run -d -p 9009:9009 registry.cn-shenzhen.aliyuncs.com/xxxx/unlimited-service-config

推荐阅读更多精彩内容