配合docker-compose的简易脚本配合上软链接实现简单命令启动关闭容器查看容器日志
作者:互联网
shell脚本
#set ff=unix!/bin/bash
cn=$2
path=/docker/bin/
start(){
docker-compose -f "$path"docker-compose-$cn.yml start
}
stop(){
docker-compose -f "$path"docker-compose-$cn.yml stop
echo "docker-compose -f "$path"docker-compose-$cn.yml stop"
}
up(){
docker-compose -f "$path"docker-compose-$cn.yml up
}
status(){
docker inspect --format '{{.State.Running}}' $cn
}
restart(){
stop
start
}
log(){
docker logs -f --tail=300 $cn
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"up")
up
;;
"log")
log
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
创建软连接
ln -s /docker/bin/dc.sh /usr/bin/dc
创建好软连接后命令使用方式
dc [start up stop status log] [container name]
比如我要启动mysql容器就执行dc start mysql
标签:容器,compose,cn,stop,配合,start,path,docker 来源: https://blog.csdn.net/qq_31143595/article/details/113463749