-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrestart-all.sh
42 lines (33 loc) · 1.04 KB
/
restart-all.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
#!/bin/bash
# variables
IMG_NAME="mjaglan/pytextsentiment"
HOST_NAME="testbed"
NETWORK_NAME=$HOST_NAME
# if desired, clean up containers
docker stop $(docker ps -a -q)
docker rm -v $(docker ps -a -q)
# if desired, clean up images
if [[ "$1" == "rmi" ]] ; then
docker rmi $(docker images -q)
fi
# build the Dockerfile
docker build -t "$IMG_NAME" "$(pwd)"
# Default docker network name is 'bridge', driver is 'bridge', scope is 'local'
# Create a new network with any name, and keep 'bridge' driver for 'local' scope.
NET_QUERY=$(docker network ls | grep -i $NETWORK_NAME)
if [ -z "$NET_QUERY" ]; then
echo "Create network >>> $NETWORK_NAME"
docker network create --driver=bridge $NETWORK_NAME
fi
# start python web application
docker run --name "$HOST_NAME" -h "$HOST_NAME" --net=$NETWORK_NAME \
-v $(pwd)/app:/tmp/app \
-p 9091:9091 \
-itd "$IMG_NAME"
# see active docker containers
docker ps
# start application service
MY_CMD="/tmp/app/run-services.sh"
docker exec -it $HOST_NAME $MY_CMD
# attach to the container
docker attach "$HOST_NAME"