forked from OxHainan/cloak-tee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-docker.sh
executable file
·77 lines (61 loc) · 1.45 KB
/
build-docker.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#/bin/bash
###########
# PURPOSE #
###########
# Run the docker image
#
# Prerequisites:
# - docker
#########
# USAGE #
#########
# To run docker interactively (mounts the current directory):
# $ path/to/build-docker.sh
#
# To run a specific command withing docker (e.g.):
# $ path/to/build-docker.sh make test
############
# SETTINGS #
############
IMAGE=avalon-evm4ccf-dev
###############
# PREPARATION #
###############
# determine directory containing this script
sysname=`uname`
if [[ $sysname =~ "Darwin" ]];then
BASEDIR="$(cd "$(dirname "$0")"; pwd)"
else
BASEDIR="$(dirname "$(readlink -f "$0")")"
fi
############################
# BUILD DOCKER #
############################
# build the docker image
sudo docker build -t $IMAGE .
# show details of each layer of the docker image
ID=$(docker images --filter=reference=$IMAGE --format "{{.ID}}")
echo $ID
docker history --format "table {{printf \"%.150s\" .CreatedBy}}\t{{.Size}}" --no-trunc $ID
##############
# RUN DOCKER #
##############
# --rm: automatically clean up the container when the container exits
# --workdir: Working directory inside the container
# -v: Bind mount a volume from the host
WORKDIR="/project/evm4ccf"
if [ $# -eq 0 ]; then
# no arguments supplied
echo "Running docker interactively..."
DIR="$(pwd)"
FLAGS="-v $DIR:$WORKDIR --workdir $WORKDIR"
else
echo "Running in docker: $@"
FLAGS="--workdir $WORKDIR"
fi
sudo docker run \
--rm
-it \
$FLAGS \
$IMAGE \
"$@"