This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
common
61 lines (49 loc) · 1.51 KB
/
common
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
#!/bin/bash
force_stop() {
docker stop $1 &> /dev/null
docker rm $1 &> /dev/null
}
inspect() {
if hash docker-machine 2>/dev/null; then
docker-machine ssh $DOCKER_MACHINE_NAME docker inspect --format=$2 $1
elif hash boot2docker 2>/dev/null; then
boot2docker ssh docker inspect --format=$2 $1
else
docker inspect --format=$2 $1
fi
}
get_ip() {
if hash docker-machine 2>/dev/null; then
docker-machine ip $DOCKER_MACHINE_NAME 2>/dev/null
elif hash boot2docker 2>/dev/null; then
boot2docker ip 2>/dev/null
else
# The following gives the ip address of the container. We
# don't need this information though. On Linux systems the
# systems can be accessed via 127.0.0.1
# docker inspect --format={{.NetworkSettings.IPAddress}} $1
echo "127.0.0.1"
fi
}
run() {
docker run "$@"
local status=$?
if [ $status -ne 0 ]; then
echo >&2
echo "Failed to start the Docker container." >&2
exit 1
fi
local container_id="$(docker ps -n=1 | tail -n 1 | awk '{print $1}')"
local container_name=$(inspect $container_id '{{.Name}}')
# strip the leading / character
container_name=${container_name#?}
local container_ip=$(get_ip $container_id)
local host_ports=$(inspect $container_id '' | \
grep HostPort | \
sed 's/[^0-9]*//g' | \
sort -nu)
echo "Container started"
echo "Name: $container_name"
echo "IP: $container_ip"
echo "Ports: $(echo $host_ports | tr '\\n' ',')"
}