-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-machine-doctor
executable file
·175 lines (149 loc) · 3.5 KB
/
docker-machine-doctor
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash -eu
if [ ! "$DOCKER_MACHINE_NAME" ] && [ "$#" -ne 1 ]; then
echo "Usage: docker-machine-doctor <name>"
exit 1
fi
NAME="${DOCKER_MACHINE_NAME:-$1}"
FS="/mnt/sda1"
if [ ! "$(which docker-machine)" ]; then
echo "Error: Could not find docker-machine executable"
exit 1
fi
STATUS="$(docker-machine status $NAME)"
if [ "$STATUS" != "Running" ]; then
echo "Error: Docker Machine $NAME not running: $STATUS"
exit 1
fi
DRIVER="$(docker-machine inspect --format="{{.DriverName}}" $NAME)"
if [ "$DRIVER" != "virtualbox" ]; then
echo "Error: Docker Machine $NAME driver not supported: $DRIVER"
exit 1
fi
_warn() {
if [ -t 1 ]; then
echo -e "\033[1;33mWarning: $@\033[0m"
else
echo "$@"
fi
}
_error() {
if [ -t 1 ]; then
echo -e "\033[1;31mError: $@\033[0m"
else
echo "$@"
fi
}
_header() {
if [ -t 1 ]; then
echo -e "\033[1;37m$@\033[0m"
else
echo "$@"
fi
}
_footer() {
echo
echo
}
_ssh() {
docker-machine ssh $NAME "$@"
}
_du() {
_ssh "sudo du -sh $@"
}
_du_top10() {
_ssh "sudo find $1 -type f -print0 | xargs -0 sudo du -a -m 2> /dev/null" \
| sort -n -r \
| ( grep -m 10 -v "^0" || : ) \
| sed "s/\([0-9]\+\)/\1M/"
}
print_docker_machine_version() {
_header "Docker machine version:"
docker-machine -version
_footer
}
print_docker_version() {
_header "Docker client and server version:"
docker version
_footer
}
print_docker_info() {
_header "Docker info:"
docker info
_footer
}
print_docker_images() {
_header "Intermediate images:"
_ssh 'docker images' | grep "^<none>" || true
_footer
}
print_docker_containers() {
_header "Containers:"
_ssh 'docker ps --all --format="table {{.ID}}\t{{.Image}}\t{{.Size}}"'
_footer
}
print_driver_storepath() {
_header "Docker machine store path:"
docker-machine inspect --format="{{.Driver.Driver.StorePath}}" $NAME
_footer
}
print_driver_fs_check_mounted() {
_header "Virtual hard drive mounted:"
local device="/dev/sda1"
local status=$(_ssh 'mount | grep "$device on $FS" > /dev/null ; echo $?')
if [ "$status" != "0" ]; then
_warn "No. Virtual hard drive not mounted!"
else
echo "Yes."
fi
_footer
}
print_driver_fs_mounts() {
_header "Filesystem mounts:"
_ssh 'sudo df -a -T -h -m' | sort -k 6 -r
_footer
}
print_driver_disk_containers() {
_header "Disk space usage: Containers:"
_du "/var/lib/docker/containers/"
echo
_du_top10 "/var/lib/docker/containers/"
_footer
}
print_driver_disk_volumes() {
_header "Disk space usage: Volumes:"
_du "/var/lib/docker/volumes/"
echo
_du_top10 "/var/lib/docker/volumes/"
_footer
}
print_driver_disk_fs() {
_header "Disk space usage: Filesystem:"
_du "/var/lib/docker/aufs/diff/"
echo
_du_top10 "/var/lib/docker/aufs/diff/"
_footer
}
print_driver_disk_temp() {
_header "Disk space usage: Temporary files:"
_du "$FS/lost+found/" "/tmp/" "/var/lib/docker/tmp/"
echo
_du_top10 "$FS/lost+found/"
_du_top10 "/tmp/"
_du_top10 "/var/lib/docker/tmp/"
_footer
}
main() {
print_docker_version
print_docker_machine_version
print_docker_info
print_docker_images
print_docker_containers
print_driver_storepath
print_driver_fs_check_mounted
print_driver_fs_mounts
print_driver_disk_containers
print_driver_disk_volumes
print_driver_disk_fs
print_driver_disk_temp
}
main