-
Notifications
You must be signed in to change notification settings - Fork 4
/
bash_aliases_docker
72 lines (62 loc) · 2.17 KB
/
bash_aliases_docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#Remove all untagged images (<none>)
function docker-rmi-none() {
docker rmi $(docker images | grep none | awk '{print $3}');
}
#Remove all containers
function docker-rm-all() {
docker rm $(docker ps -aq)
}
#Stop all containers
function docker-stop-all() {
docker stop $(docker ps -q)
}
#Run a container
#If CMD is not provided, uses bash, adds name in format tmp$NUMBER_OF_RUNNING_TMP_CONTS
function dr() {
cmd="bash"
image=$1
[ $# -ge 2 ] && shift && cmd=$@
run="docker run --name tmp$(docker ps -a | grep tmp | wc -l) -it --rm $image $cmd"
echo $run
$run
}
#Call docker load. If the image is not specified by path, use default directory
function dl() {
local path=$1
local DEFAULT_PATH="${HOME}/devel/brew/"
[[ "${path}" =~ ^.*/.*$ ]] || path=${DEFAULT_PATH}${path}
docker load -i ${path}
}
#Docker exec
#Use bash as a default CMD, if no container is specified, use last container from docker ps list
function de() {
local cmd=bash
local container=$1
[ -z "$1" ] && container=$(docker ps | tail -1 | awk '{print $1}')
[ "$container" == "CONTAINER" ] && >&2 echo "No running container" && return 0
[ $# -ge 2 ] && shift && cmd=$@
docker exec -it $container $cmd
}
#Docker inspect/ip
#Get an IP address of a container - if no container is specified, use last container from docker ps list
function di() {
local container=$1
[ -z "$1" ] && container=$(docker ps | tail -1 | awk '{print $1}')
[ "$container" == "CONTAINER" ] && >&2 echo "No running container" && return 0
docker inspect $container | jq -r .[0].NetworkSettings.IPAddress
}
#Docker kill
#Kill the specified container, if no container is specified, use last container from docker ps list
function dk() {
local container=$1
[ -z "$1" ] && container=$(docker ps | tail -1 | awk '{print $1}')
[ "$container" == "CONTAINER" ] && >&2 echo "No running container" && return 0
docker kill $container
}
function docker-build() {
dockerfile="Dockerfile"
[ -e "$dockerfile" ] || return 1
build_cmd=$(cat $dockerfile | grep LABEL | grep -i build | cut -d " " -f 3-)
echo "Running a Build label from $dockerfile: $build_cmd"
$build_cmd
}