-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_container.sh
27 lines (22 loc) · 689 Bytes
/
run_container.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
#!/bin/bash
image_name='webserv_webserv'
# Run your docker command and capture the output
output=$(docker ps)
# Extract the container ID and name from the output
container_id=$(echo "$output" | awk 'NR==2 {print $1}')
container_name=$(echo "$output" | awk 'NR==2 {print $2}')
if [[ $container_name == $image_name ]]; then
make fclean
docker compose down
echo 'Container is down.'
else
docker compose up -d
sleep 3s
echo 'Container starts up.'
output=$(docker ps)
container_id=$(echo "$output" | awk 'NR==2 {print $1}')
container_name=$(echo "$output" | awk 'NR==2 {print $2}')
fi
# Output the results
echo "Container ID: $container_id"
echo "Container Name: $container_name"