2
0

docker-entrypoint.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. set -e
  3. # Warn if the DOCKER_HOST socket does not exist
  4. if [[ $DOCKER_HOST = unix://* ]]; then
  5. socket_file=${DOCKER_HOST#unix://}
  6. if ! [ -S "$socket_file" ]; then
  7. cat >&2 <<-EOT
  8. ERROR: you need to share your Docker host socket with a volume at $socket_file
  9. Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\`
  10. See the documentation at http://git.io/vZaGJ
  11. EOT
  12. socketMissing=1
  13. fi
  14. fi
  15. # Generate dhparam file if required
  16. /app/generate-dhparam.sh
  17. # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in []
  18. RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g'); export RESOLVERS
  19. SCOPED_IPV6_REGEX="\[fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}\]"
  20. if [ "$RESOLVERS" = "" ]; then
  21. echo "Warning: unable to determine DNS resolvers for nginx" >&2
  22. unset RESOLVERS
  23. elif [[ $RESOLVERS =~ $SCOPED_IPV6_REGEX ]]; then
  24. echo -n "Warning: Scoped IPv6 addresses removed from resolvers: " >&2
  25. echo "$RESOLVERS" | grep -Eo "$SCOPED_IPV6_REGEX" | paste -s -d ' ' >&2
  26. RESOLVERS=$(echo "$RESOLVERS" | sed -r "s/$SCOPED_IPV6_REGEX//g" | xargs echo -n); export RESOLVERS
  27. fi
  28. # If the user has run the default command and the socket doesn't exist, fail
  29. if [ "$socketMissing" = 1 ] && [ "$1" = forego ] && [ "$2" = start ] && [ "$3" = '-r' ]; then
  30. exit 1
  31. fi
  32. exec "$@"