-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.sh
64 lines (55 loc) · 1.58 KB
/
docker.sh
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
# docker-compose shortcut
alias dc='docker-compose'
# docker-machine shortcut
alias dm='docker-machine'
# Utilities for managing multiple docker-machines.
#
# NOTE: This is all much easier with the use of docker-machine-ipconfig:
# https://github.com/fivestars/docker-machine-ipconfig
#
# It allows you to assign static IPs to each docker-machine VM so you
# don't have to worry about boot order messing up your hosts file or
# requiring you to renegerate certificates
DMC_FILE=~/.current-docker-machine
# dmc-env
# Sets docker environment variables in the current sessions for the
# preferred/current machine.
function dmc-env {
machine=$(_dmc-get-current)
if [ -z "$machine" ]; then
echo 'Preferred machine is not set (use dmc-set)'
return 1
fi
eval $(docker-machine env $machine)
}
# dmc-set
# Sets preferred/current machine, which will be used for all sessions until
# dmc-set is called again for a different machine).
function dmc-set {
machine="$1"
if [ -z "$machine" ]; then
echo 'Must specify a machine: `dmc-set mymachine`'
return 1
fi
export CURRENT_DOCKER_MACHINE="$machine"
_dmc-write "$machine"
dmc-env
}
function _dmc-get-current {
if [ -n "$CURRENT_DOCKER_MACHINE" ]; then
echo "$CURRENT_DOCKER_MACHINE"
else
if [ -f "$DMC_FILE" ]; then
echo $(cat "$DMC_FILE")
fi
fi
}
function _dmc-write {
machine="$1"
if [ -n "$machine" ]; then
echo "$machine" > $DMC_FILE
fi
}
# Call dmc-env when session starts, if there's a current/preferred machine.
machine=$(_dmc-get-current)
[[ -n $machine ]] && dmc-env