-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_docker
executable file
·37 lines (32 loc) · 1.28 KB
/
run_docker
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
#!/bin/bash
# Attempt to change directory to the directory containing the script
script_dir=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
cd "$script_dir" || {
echo "Error: Failed to change to the script's directory. Please check the path."
exit 1
}
# echo out the current directory
echo "Running docker-compose in $(pwd)"
# parse the published port in the docker-compose.yml file
port=$(grep -A 1 "ports:" docker-compose.yml | grep "published" | cut -d ':' -f 2 | tr -d '[:space:]')
echo "Starting docker-compose on port $port"
if command -v python3 &>/dev/null; then
alias python=python3
PYTHON_CMD=python3
elif command -v python &>/dev/null; then
PYTHON_CMD=python
else
echo "Neither python nor python3 is available. Exiting."
exit 1
fi
if ! docker info > /dev/null 2>&1; then
echo "Error: Docker is not running. Please start Docker and try again."
exit 1
fi
docker-compose down --rmi all
echo -e "\n##########################\n# Launching a web browser to http://localhost:$port in 20 seconds"
echo -e "# If you don't see a web browser, please open one and navigate to http://localhost:$port\n##########################\n"
# finish
echo "Starting docker-compose in $(pwd)"
(sleep 20; $PYTHON_CMD -c "import webbrowser; webbrowser.open('http://localhost:$port')") &
docker-compose up