-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker.bash.functions
113 lines (96 loc) · 2.86 KB
/
docker.bash.functions
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
#!/bin/echo Do not execute/subshell me. Source me.
DM_ACTIVE_MACHINE_FILTER=Running
DOCKER_VIM_IMAGE=dudymas/toolbox:vim
function doc-tags() {
if [ "$#" -eq 0 ] ; then
echo List tags for an image in hub.docker.com
echo 'Usage: doc-tags <image-name>'
else
curl -s -S "https://registry.hub.docker.com/v2/repositories/$1/tags/" | jq '."results"[]["name"]' |sort
fi
}
function dvim() {
if [ $# -eq 0 ] ; then
echo 'Usage: dvim <Container with volumes> <optional file/folder to edit>'
else
docker run -it --rm --volumes-from $1 $DOCKER_VIM_IMAGE ${@:2}
fi
}
function dm-list() {
dma ls | grep -v error
}
function get-dms() {
dm-list | grep $1 | awk '{ print $1 }'
}
function denv() {
eval $(docker-machine env $1)
}
function denv-attach-to-swarm-port() {
export DOCKER_HOST=${$DOCKER_HOST%:*}:$1
echo DOCKER_HOST=$DOCKER_HOST
}
function drun() {
pattern=$1
shift
for dm in $(get-dms $pattern) ; do
eval $(dma env $dm)
echo --- $dm ---
doc $@
done
}
function drun() {
for dm in $(get-dms $DM_ACTIVE_MACHINE_FILTER) ; do
dma active $dm
eval $(dma env)
doc $@
done
}
function remake-all() {
for dm in $(get-dms $DM_ACTIVE_MACHINE_FILTER) ; do
dma active $dm
eval $(dma env)
make build
make clean $@
make deploy $@
done
}
function dmon() {
MACHINE_STORAGE_PATH=$PWD
if [ $# -ne 0 ] ; then
MACHINE_STORAGE_PATH=$MACHINE_STORAGE_PATH/$1
fi
echo "NOTE: machines will be created in $MACHINE_STORAGE_PATH/machines"
echo "If you close this shell, be sure to export 'MACHINE_STORAGE_PATH=$MACHINE_STORAGE_PATH/machines' to use this env later."
export MACHINE_STORAGE_PATH
}
function dmoff() {
echo "NOTE: machines will be created in $HOME/.docker/machine/machines"
unset MACHINE_STORAGE_PATH
}
function doc-clean-images() {
docker rmi $(docker images -f dangling=true -q)
}
function docker-machine-convert-config {
if [[ "$(which jq)" == "" ]]; then
echo Please install jq \(i.e. brew install jq \)...
echo jq is used to parse configs.
return
fi
MACHINE_CONFIG=$1
NEW_STORE=$2
BAD_STORE_JSON_PATH=$3
OLD_STORE=$(jq -r "${BAD_STORE_JSON_PATH}" < $MACHINE_CONFIG)
echo Updating $MACHINE_CONFIG
echo Moving $OLD_STORE to $NEW_STORE
sed -i '' "s^$OLD_STORE^$NEW_STORE^g" $MACHINE_CONFIG
}
function docker-machine-move-configs {
MACHINE_STORAGE_PATH=${MACHINE_STORAGE_PATH:-$PWD}
for config in $MACHINE_STORAGE_PATH/machines/*/config.json ; do
#docker-machine-convert-config $config $MACHINE_STORAGE_PATH '.HostOptions.AuthOptions.StorePath'
docker-machine-convert-config $config $MACHINE_STORAGE_PATH '.Driver.StorePath'
done
}
function docker-set-api-version() {
export DOCKER_API_VERSION=${1:-1.22}
}