-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.sh
More file actions
52 lines (38 loc) · 1.01 KB
/
exec.sh
File metadata and controls
52 lines (38 loc) · 1.01 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
#!/usr/bin/bash
# We use this script to start and enter a container base on user input.
# Creating a variable call NAME.
NAME="Enter container name"
# Show docke=r version
echo "Your docker version is"
docker -v
# Hold the terminal for few seconds
sleep 3
: '
# Displaying the number of containers present
echo "Your docker containers are: "
docker ps -a
# Hold the terminal for few seconds
sleep 5
'
# Ask container name from the user
echo $NAME
read container_name
# Displaying the number of containers present
echo "Your docker containers is:"
docker ps -a | grep $container_name #| awk '{print $7}'
# Hold the terminal for few seconds
sleep 5
# Checking the state of the container.
RUNNING=$(docker inspect --format="{{.State.Running}}" $container_name)
if [ "$RUNNING" == "false" ]; then
echo "Starting $container_name"
docker start $container_name
fi
: '
# Start my container
docker start $container_name
#Hold the terminal for few seconds
sleep 3
'
# Enter my container
docker exec -it $container_name bash