-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.sh
executable file
·63 lines (53 loc) · 1.65 KB
/
manage.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
#/bin/bash
IMAGE="viliusl/ubuntu-sshd-nginx"
BUILD_CMD="sudo docker build -rm=true -t=$IMAGE ."
RUN_CMD="sudo docker run -d -p 55522:22 -p 55580:80 $IMAGE"
SSH_CMD="ssh root@localhost -p 55522"
ID=`sudo docker ps | grep "$IMAGE" | head -n1 | cut -d " " -f1`
is_running() {
[ "$ID" ]
}
case "$1" in
build)
echo "Building Docker image: '$IMAGE'"
$BUILD_CMD
;;
start)
if is_running; then
echo "Image '$IMAGE' is already running under Id: '$ID'"
exit 1;
fi
echo "Starting Docker image: '$IMAGE'"
$RUN_CMD
echo "Docker image: '$IMAGE' started"
;;
stop)
if is_running; then
echo "Stopping Docker image: '$IMAGE' with Id: '$ID'"
sudo docker stop "$ID"
echo "Docker image: '$IMAGE' with Id: '$ID' stopped"
else
echo "Image '$IMAGE' is not running"
fi
;;
status)
if is_running; then
echo "Image '$IMAGE' is running under Id: '$ID'"
else
echo "Image '$IMAGE' is not running"
fi
;;
ssh)
if is_running; then
echo "Attaching to running image '$IMAGE' with Id: '$ID'"
$SSH_CMD
else
echo "Image '$IMAGE' is not running"
fi
;;
*)
echo "Usage: $0 {build|start|stop|status|ssh}"
exit 1
;;
esac
exit 0