-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage-docker
More file actions
executable file
·83 lines (59 loc) · 2.14 KB
/
manage-docker
File metadata and controls
executable file
·83 lines (59 loc) · 2.14 KB
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
#!/bin/bash
CURRENT_DIR=$(dirname $(readlink -f $0))
DOCKER_REGISTRY="repo.acip.io"
COMMAND=$1
if [ "$#" -lt 1 ]; then
echo "
Usage: manage-docker [COMMAND] [PARAMETERS]
A script that handles docker image process
Commands:
login [username password] : logs you in to $DOCKER_REGISTRY
images : lists locally available images (*)
push [image_label] : pushes image_label to $DOCKER_REGISTRY
pull [image_label] : pulls and saves image_label from $DOCKER_REGISTRY into /srv/repo/
load [image_path] [config_file] : loads given image as a docker image (*)
Parameters:
username : username for repo
password : user password for repo
image_label : name of the image (format: $DOCKER_REGISTRY/image_name)
(*) works on non-connected devices
"
else
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
if [ $1 = "login" ]; then
USERNAME=$2
PASSWORD=$3
docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY
fi
if [ $1 = "push" ]; then
IMAGE_LABEL=$2
docker push "$DOCKER_REGISTRY"'/'"$IMAGE_LABEL"
fi
if [ $1 = "pull" ]; then
IMAGE_LABEL=$2
#readarray -d / -t arr <<< $IMAGE_LABEL
docker pull "$DOCKER_REGISTRY"'/'"$IMAGE_LABEL"
docker save "$DOCKER_REGISTRY"'/'"$IMAGE_LABEL" | gzip -c > '/srv/repo/'"$IMAGE_LABEL"'.tar.gz'
fi
fi
if [ $1 = "images" ]; then
IMAGE_LABEL=$2
docker images
fi
if [ $1 = "load" ]; then
IMAGE_PATH=$2
# get image label from path (by excluding the path itself and .tar.gz extension)
IMAGE_NAME=$(basename $IMAGE_PATH)
readarray -d . -t IMAGE_LABEL <<< $IMAGE_NAME
docker load -i $IMAGE_PATH
echo "$IMAGE_LABEL"' has been loaded successfully!'
UUID="$(docker run -d "$DOCKER_REGISTRY"'/'"$IMAGE_LABEL")"
if [ ! -z "$3" ]; then
CONFIG_FILE=$3
CONFIG_FILE_NAME=$(basename $CONFIG_FILE)
docker cp $CONFIG_FILE "$UUID"':/client/config/'"$CONFIG_FILE_NAME"
fi
echo "$IMAGE_LABEL"' is running with '"$UUID"' ID!'
fi
fi