docker-entrypoint.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 jwilder/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. # Note: if $DHPARAM_BITS is not defined, generate-dhparam.sh will use 2048 as a default
  17. # Note2: if $DHPARAM_GENERATION is set to false in environment variable, dh param generator will skip completely
  18. /app/generate-dhparam.sh $DHPARAM_BITS $DHPARAM_GENERATION
  19. # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in []
  20. export RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g')
  21. SCOPED_IPV6_REGEX="\[fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}\]"
  22. if [ "x$RESOLVERS" = "x" ]; then
  23. echo "Warning: unable to determine DNS resolvers for nginx" >&2
  24. unset RESOLVERS
  25. elif [[ $RESOLVERS =~ $SCOPED_IPV6_REGEX ]]; then
  26. echo -n "Warning: Scoped IPv6 addresses removed from resolvers: " >&2
  27. echo $RESOLVERS | grep -Eo $SCOPED_IPV6_REGEX | paste -s -d ' ' >&2
  28. export RESOLVERS=$(echo $RESOLVERS | sed -r "s/$SCOPED_IPV6_REGEX//g" | xargs echo -n)
  29. fi
  30. # If the user has run the default command and the socket doesn't exist, fail
  31. if [ "$socketMissing" = 1 -a "$1" = forego -a "$2" = start -a "$3" = '-r' ]; then
  32. exit 1
  33. fi
  34. exec "$@"