-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_container.sh
More file actions
executable file
·32 lines (29 loc) · 928 Bytes
/
run_container.sh
File metadata and controls
executable file
·32 lines (29 loc) · 928 Bytes
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
#!/bin/bash
#
# shell script for run container or start&attach container easily
#
# Usage: ./run_container.sh
# create by c4fiber<qudcjf153@gmail.com>
CONTAINER_NAME=lets-practice-linux-cli
IMAGE_NAME=hayanbada/linux-cli-prac
VOLUME=linux-cli-prac_data
# create volume if it is not exist
docker volume inspect linux-cli-prac_data > /dev/null
if [ $? -eq 0 ]; then
echo "volume: linux-cli-prac_data already exist"
else
echo "create new volume: $VOLUME"
docker volume create "$VOLUME" > /dev/null
fi
# Does container already exist?
EXISTING_CONTAINER=$(docker ps -a \
--filter "name=^${CONTAINER_NAME}$" \
--format "{{.Names}}")
if [ "$EXISTING_CONTAINER" = "$CONTAINER_NAME" ]; then
echo "container: $CONTAINER_NAME already exists "
docker start -ai "$CONTAINER_NAME"
else
echo "create new container: $CONTAINER_NAME"
docker run -it --name "$CONTAINER_NAME" \
-v $VOLUME:/home/myuser "$IMAGE_NAME" /bin/bash
fi