-
Notifications
You must be signed in to change notification settings - Fork 25
/
run_docker.sh
executable file
·59 lines (47 loc) · 1.57 KB
/
run_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
#!/bin/bash
#
# Docker build image, run container, execute last container.
#
# - Author: Jongkuk Lim
# - Contact: [email protected]
xhost +
ORG=jmarpledev
PRJ_NAME=${PWD##*/}
PRJ_NAME=${PRJ_NAME,,}
DOCKER_TAG=$ORG/$PRJ_NAME
CMD_ARGS=( ${@} )
CMD_ARGS=${CMD_ARGS[*]:1}
if [[ $2 == :* ]]; then
DOCKER_TAG=$DOCKER_TAG$2
CMD_ARGS=${CMD_ARGS[*]:2}
fi
if [ "$1" = "build" ]; then
echo "Building a docker image with tagname $DOCKER_TAG and arguments $CMD_ARGS"
docker build . -t $DOCKER_TAG $CMD_ARGS --build-arg UID=`id -u` --build-arg GID=`id -g`
elif [ "$1" = "run" ]; then
echo "Run a docker image with tagname $DOCKER_TAG and arguments $CMD_ARGS"
docker run -tid --privileged --gpus all \
-e DISPLAY=${DISPLAY} \
-e TERM=xterm-256color \
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
-v /dev:/dev \
-v $PWD:/home/user/$PRJ_NAME \
--network host \
$CMD_ARGS \
$DOCKER_TAG /bin/bash
last_cont_id=$(docker ps -qn 1)
echo $(docker ps -qn 1) > $PWD/.last_exec_cont_id.txt
docker exec -ti $last_cont_id /bin/bash
elif [ "$1" = "exec" ]; then
echo "Execute the last docker container"
last_cont_id=$(tail -1 $PWD/.last_exec_cont_id.txt)
docker start ${last_cont_id}
docker exec -ti ${last_cont_id} /bin/bash
else
echo ""
echo "============= $0 [Usages] ============"
echo "1) $0 build : build docker image"
echo " build --no-cache : Build docker image without cache"
echo "2) $0 run : launch a new docker container"
echo "3) $0 exec : execute last container launched"
fi