run.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # Use available command to determine if port is open
  3. is_port_open() {
  4. local port=$1
  5. if command -v netstat >/dev/null 2>&1; then
  6. netstat -tuln | grep -q ":$port "
  7. return $?
  8. elif command -v lsof >/dev/null 2>&1; then
  9. lsof -i :$port | grep -q LISTEN
  10. return $?
  11. elif command -v sockstat >/dev/null 2>&1; then
  12. sockstat -4l | grep -q ":$port "
  13. return $?
  14. else
  15. echo "Error: Could not find netstat, lsof, or sockstat. Unable to check if port is open."
  16. exit 1
  17. fi
  18. }
  19. port8080=${1:-yes}
  20. if [[ "$port8080" == "yes" ]]; then
  21. if is_port_open 8080; then
  22. echo "Error: Port 8080 is already in use!"
  23. exit 1
  24. fi
  25. echo
  26. echo "It's possible to visit http://localhost:8080/ after the docker image has launched"
  27. echo
  28. docker run --mount type=bind,source="$PWD/config",destination=/etc/algernon,readonly --publish 8080:80 --rm hello
  29. else
  30. if is_port_open 80 || is_port_open 443; then
  31. echo "Error: Either Port 80 or 443 (or both) are already in use!"
  32. exit 1
  33. fi
  34. echo
  35. echo "It's possible to visit http://localhost/ and https://localhost/ after the docker image has launched, if docker has the right permissions"
  36. echo
  37. docker run --mount type=bind,source="$PWD/config",destination=/etc/algernon,readonly --publish 80:80 --publish 443:443 --rm hello
  38. fi