Created
July 17, 2015 06:31
-
-
Save tianweidut/1c276faaa85c3433c29a to your computer and use it in GitHub Desktop.
shell 技巧: 1. exec 一个shell func: export -f func_name; exec bash -c “func_name” 2. 判断命令输出是否为空 if [[ -n $(docker ps -f name=test)]]; 3. 判断命令的返回码是否为0(即是否正确执行exit 0) if docker ps ;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| ulimit -n 65536 | |
| exec 2>&1 | |
| create_container () { | |
| echo 'try to create container' | |
| sudo docker create --name 'gentoo_with_portage' \ | |
| -v /usr/portage/ \ | |
| -v /var/lib/layman/ \ | |
| -v /var/cache/edb/ \ | |
| -v /etc/portage/package.keywords/ \ | |
| -v /etc/portage/package.mask/ \ | |
| -v /etc/portage/package.unmask/ \ | |
| docker-registry.intra.douban.com/gentoo_with_portage:latest true | |
| echo 'finish create container' | |
| } | |
| check_container () { | |
| while true; do | |
| if [[ -n $(sudo docker ps -q -a -f name='gentoo_with_portage') ]] ; then | |
| echo 'container exists, continue...' | |
| sleep 5 | |
| else | |
| echo 'no gentoo_with_portage container, will exit' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment