-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.docker_bash
160 lines (131 loc) · 4.22 KB
/
.docker_bash
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#function dpn() {
#docker ps -a | head -1
#local CONTAINERS="$(diff --unchanged-group-format= --changed-group-format=%\> <(dp -q | sort) <(dpa -q | sort) | tr '\n' '|' | sed 's/.$//')"
#if [ -z $CONTAINERS ]; then
# return
#fi
#docker ps -a | egrep "($CONTAINERS)"
#}
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/dunk/.docker/machine/machines/dev"
export DOCKER_MACHINE_NAME="dev"
DOCKER_PSFORMAT='table {{.Names}}\t{{.Image}}\t{{.ID}}\t{{.Command}}\t{{.Status}}'
DOCKER_PSFORMAT_NAMES_ONLY='{{.Names}}'
alias d='docker'
alias di='docker images'
alias dirm='docker rmi'
alias fig='docker-compose'
function dp() {
docker ps --format "$DOCKER_PSFORMAT" "$@"
}
function dpa() {
dp -a
}
function dpn() {
dp --filter 'status=exited'
}
# Remove container, and clean up volumes so that they are not orphaned
alias drm='docker rm -v'
function docker_container_names() {
docker ps -a --format "$DOCKER_PSFORMAT_NAMES_ONLY" | xargs
}
function drma() {
docker kill $(docker_container_names)
docker rm -v $(docker_container_names)
}
alias dh='docker history'
# Clean up untagged images
function dcln() {
docker rmi $(docker images | grep "^<none>" | tr -s " " | cut -d" " -f3)
}
# Run a quick, ephemeral ubuntu container
alias drun='docker run -it --rm ubuntu bash'
# Container statistics across all containers
function dstat() {
docker stats $(docker_container_names)
}
# Container processes across all containers
function dtop() {
for container in $(docker_container_names); do
echo "*************** {{$container}} ****************"
docker top $container
echo -e "\n"
done
}
# Drop into a shell on a container
function de() {
docker exec -it $* bash
}
# Strip the history out of an image. Seldom needed.
function docker_flatten() {
ID=$(docker run -d $1 /bin/bash)
docker export $ID | docker import – $2
docker kill $ID
docker rm -v $ID
}
# Get the ip address of a particular container
dip() {
local network
network='pipeline'
docker inspect --format "{{ .NetworkSettings.Networks.$network.IPAddress }}" "$@"
}
# Get the ip addresses of all containers
dipall() {
for container_name in $(docker_container_names);
do
local container_ip=$(dip $container_name)
if [[ -n "$container_ip" ]]; then
echo $(dip $container_name) " $container_name"
fi
done | sort -t . -k 3,3n -k 4,4n
}
# Run an image
dr() {
docker run -it --rm $1 bash
}
CONTAINERS='auditor deliveryapiconsumer sgeserver rabbit deliveryapi deliverydb orchestrator sampletrackingdb web sgeconsumer'
function _docker_container_name() {
local current_arg
#local options
current_arg="${COMP_WORDS[COMP_CWORD]}"
#options=($( docker ps -a --format "{{.Names}}" ))
# The delay contacting docker for this is annoying, and it's a static list for the most part anyways
#COMPREPLY=( $(compgen -W "$(docker ps -a --format '{{.Names}}')" -- "${current_arg}") )
COMPREPLY=( $(compgen -W "$CONTAINERS" -- "${current_arg}") )
}
function _docker_image_name() {
current_arg="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$(docker images | tr -s ' ' | cut -d ' ' -f1,2 | sed 's/ /:/' | tail -n +2 | xargs)" -- "${current_arg}") )
}
complete -F _docker_container_name drm
complete -F _docker_container_name de
complete -F _docker_container_name dip
complete -F _docker_image_name dirm
complete -F _docker_image_name dr
complete -F _docker_image_name dh
complete -F _docker_image_name docker_flatten
function dhelp() {
echo "Available docker commands:
--------
Containers
----
dp list all running containers
dpa list all containers, running or not
dpn list all not running containers
drm remove a specified container
drma remove all containers
de drop into a shell on a container
drun run an ephemeral ubuntu container
Images
----
di list all images
dirm remove a specified image
dh show the history for an image
dr run an image in an ephemeral container
dcln clean up orphaned images with no tag
Assorted
----
dstat show statistics across all containers
dtop show processes across all containers"
}