生产实践:
1.根据docker容器名或id进入容器
2.查看docker容器日志
学习技巧:
if then else fi 语句的用法
脚本内容:
#!/bin/bash ############################################################ # $Name: dksh # $Version: v1.0 # $Function: docker in and print container logs # $Author: Zhihe An # $Copyright (c) https://chegva.com # $Create Date: 2017-04-12 ############################################################ #First: cp dksh /usr/local/bin && chmod +x /usr/local/bin/dksh #Add Env PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH if [ "$1" == "" ]; then echo "Usage: `basename $0` [container name or id] `basename $0` logs [container name or id]"; exit; fi if [ $# -eq 1 ]; then docker exec -it $1 /bin/bash -l; exit; fi if [ $# -eq 2 ] then if [ "$1" == "logs" ]; then docker logs -f $2; exit; else echo "Usage: `basename $0` [container name or id] `basename $0` logs [container name or id]"; fi else echo "Usage: `basename $0` [container name or id] `basename $0` logs [container name or id]"; exit; fi exit 0
脚本使用: