From ba678651d9078a1c5de108f6aacd771ef3eecc1b Mon Sep 17 00:00:00 2001 From: Werner Beroux Date: Mon, 22 Jun 2015 14:03:40 +0200 Subject: [PATCH] Initial version. --- Dockerfile | 24 ++++++++++++++++++ README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++- ngrok.yml | 1 + ngrok_discover | 58 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 ngrok.yml create mode 100755 ngrok_discover diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8be35e2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM busybox:ubuntu-14.04 +MAINTAINER Werner Beroux + +# Install ngrok +ADD https://dl.ngrok.com/ngrok_2.0.19_linux_amd64.zip /ngrok.zip +RUN unzip -o ngrok.zip -d /bin && \ + false || rm -f ngrok.zip + +# Add config script +ADD ngrok.yml /home/ngrok/.ngrok2/ +ADD ngrok_discover /bin/ngrok_discover + +# Create non-root user +RUN echo 'ngrok:x:6737:6737:Ngrok user:/home/ngrok:/bin/false' >> /etc/passwd +RUN echo 'ngrok:x:6737:' >> /etc/group +RUN chown ngrok:ngrok /home/ngrok +RUN chmod -R go=u,go-w /home/ngrok +RUN chmod go= /home/ngrok + +USER ngrok + +EXPOSE 4040 + +ENTRYPOINT '/bin/ngrok_discover' diff --git a/README.md b/README.md index 83d5aaa..ce007be 100644 --- a/README.md +++ b/README.md @@ -1 +1,65 @@ -# docker-ngrok +# ngrok + +A [Docker][docker] image for [ngrok][ngrok] v2, introspected tunnels to localhost. +It's based on the excellent work of [wizardapps/ngrok][wizardapps/ngrok] and [fnichol/ngrok][fnichol/ngrok]. + + +## Features + + * Small: Built using [busybox][busybox]. + * Safe: Runs as non-root user with a random UID `6737` (to avoid mapping to an existing UID). + * Simple: Just link as `http` or `https` in most cases, see below; exposes ngrok server 4040 port. + + +## Configuration + +You simply have to link the Ngrok container to the application under the `app` or `http` or `https` aliases, and all of the configuration will be done for you by default. + +Additionally, you can specify one of several environment variable (via `-e`) to configure your Ngrok tunnel: + + * `NGROK_AUTH` - Authentication key for your Ngrok account. This is needed for custom subdomains, custom domains, and HTTP authentication + * `NGROK_SUBDOMAIN` - Name of the custom subdomain to use for your tunnel. You must also provide the authentication token + * `NGROK_DOMAIN` - Paying Ngrok customers can specify a custom domain. Only one subdomain or domain can be specified, with the domain taking priority. + * `NGROK_USERNAME` - Username to use for HTTP authentication on the tunnel. You must also specify an authentication token + * `NGROK_PASSWORD` - Password to use for HTTP authentication on the tunnel. You must also specify an authentication token + * `NGROK_PROTOCOL` - Can either be “HTTP” or “TCP”, and it defaults to “HTTP” if not specified. If set to “TCP”, Ngrok will allocate a port instead of a subdomain and proxy TCP requests directly to your application. + +To see command-line options, run `docker run --rm wernight/ngrok --help`. + + +## Usage example + + 1. We'll set up a simple example HTTP server in a docker container named `www`: + + $ docker run -v /usr/share/nginx/html --name www_data busybox true + $ docker run --rm --volumes-from www_data busybox /bin/sh -c 'echo "

Yo

" > /usr/share/nginx/html/index.html' + $ docker run -d -p 80 --volumes-from www_data --name www nginx + $ curl $(docker port www 80) +

Yo

+ + 2. Now we'll link that HTTP server into an ngrok container to expose it on the internet: + + $ docker run -d -p 4040 --link www:http --name www_ngrok wernight/ngrok + + 3. You can now access the [API][ngrok-api] to find the assigned domain: + + $ curl $(docker port www_ngrok 4040)/api/tunnels + + or access the web UI to see requests and responses: + + $ xdg-open http://$(docker port www_ngrok 4040) + + +## Feedbacks + +Report issues/questions/feature requests on [GitHub Issues][issues] + +Pull requests are very welcome! + +[issues]: https://github.com/wernight/docker-ngrok/issues +[docker]: https://www.docker.io/ +[ngrok]: https://ngrok.com/ +[ngrok-api]: https://ngrok.com/docs#client-api +[busybox]: https://registry.hub.docker.com/_/busybox +[wizardapps/ngrok]: https://registry.hub.docker.com/u/wizardapps/ngrok/ +[fnichol/ngrok]: https://registry.hub.docker.com/u/fnichol/ngrok/ diff --git a/ngrok.yml b/ngrok.yml new file mode 100644 index 0000000..6480f00 --- /dev/null +++ b/ngrok.yml @@ -0,0 +1 @@ +web_addr: 0.0.0.0:4040 diff --git a/ngrok_discover b/ngrok_discover new file mode 100755 index 0000000..67b3fc0 --- /dev/null +++ b/ngrok_discover @@ -0,0 +1,58 @@ +#!/bin/sh + +if [ "$1" = "/bin/sh" ]; then + shift +fi + +if [ -n "$HTTPS_PORT" ]; then + FWD="`echo $HTTPS_PORT | sed 's|^tcp://||'`" +elif [ -n "$HTTP_PORT" ]; then + FWD="`echo $HTTP_PORT | sed 's|^tcp://||'`" +elif [ -n "$APP_PORT" ]; then + FWD="`echo $APP_PORT | sed 's|^tcp://||'`" +fi + +ARGS="" + +if [ -n "$NGROK_AUTH" ]; then + ARGS="-authtoken=$NGROK_AUTH " +fi + +# Set the subdomain or hostname, depending on which is set +if [ -n "$NGROK_HOSTNAME" ] && [ -n "$NGROK_AUTH" ]; then + ARGS="$ARGS -hostname=$NGROK_HOSTNAME " +elif [ -n "$NGROK_SUBDOMAIN" ] && [ -n "$NGROK_AUTH" ]; then + ARGS="$ARGS -subdomain=$NGROK_SUBDOMAIN " +elif [ -n "$NGROK_HOSTNAME" ] || [ -n "$NGROK_SUBDOMAIN" ]; then + if [ -z "$NGROK_AUTH" ]; then + echo "You must specify an authentication token after registering at https://ngrok.com to use custom domains." + exit 1 + fi +fi + +if [ -n "$NGROK_HEADER" ]; then + ARGS="$ARGS -host-header=$NGROK_HEADER " +fi + +PROTOCOL="http" + +if [ "$NGROK_PROTOCOL" == "TCP" ]; then + PROTOCOL="tcp " +fi + +if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then + ARGS="$ARGS -auth=\"$NGROK_USERNAME:$NGROK_PASSWORD\" " +elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then + if [ -z "$NGROK_AUTH" ]; then + echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication." + echo "Sign up for an authentication token at https://ngrok.com" + exit 1 + fi +fi + +case "$1" in + -h|help) ARGS=$1 ;; + *) ARGS="$PROTOCOL $ARGS -log stdout $* $FWD" ;; +esac + +exec /bin/ngrok $ARGS