Git Product home page Git Product logo

plex-ngrok-docker's Introduction

This docker will use Ngrok to create a tunnel between your internal plex server to an outside url. Then will update the plex "Custom server access URLs" with the random Ngrok URL using PlexAPI. This allows you to login to plex.tv from any device and have a direct connection to your home plex server. Works from behind Carrier Grade NAT/double NAT and possibly VPN's.

Variable needed are:

Open TCP port 4040 in the Unraid ngrok docker web interface

NGROK_PORT = 32400

NGROK_AUTH = Ngrok Authtoken from their website after you've created an account

PLEX_TOKEN = Plex Authtoken

PLEX_BASE_URL = Plex server url like http://192.168.0.21:32400

NGROK_PROTOCOL = set as TCP

Below is the original docker info from wernight. This is a fork with a custom python script, PlexAPI and python 3 installed.

Docker repository Build passing Codenvy badge

Supported tags and respective Dockerfile links

A Docker image for ngrok v2, introspected tunnels to localhost. It's based on the excellent work of wizardapps/ngrok and fnichol/ngrok.

Features

  • Small: Built using busybox.
  • Simple: Just link as http or https in most cases, see below; exposes ngrok server 4040 port.
  • Secure: Runs as non-root user with a random UID 6737 (to avoid mapping to an existing UID).

Configuration

To see command-line options, run docker run --rm wernight/ngrok ngrok --help.

Usage

Supposing you've an Apache or Nginx Docker container named web_service_container listening on port 80:

$ docker run --rm -it --link web_service_container wernight/ngrok ngrok http web_service_container:80

Environment variables

Please consider using directly the command-line arguments of Ngrok.

If you use the default CMD (i.e. don't specify the ngrok command-line but only wernight/ngrok), then you can use instead envrionment variables magic below.

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_HOSTNAME - 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.
  • NGROK_PORT - Port to expose (defaults to 80 for HTTP protocol).
  • NGROK_REGION - Location of the ngrok tunnel server; can be us (United States, default), eu (Europe), ap (Asia/Pacific) or au (Australia)
  • NGROK_BINDTLS - Toggle tunneling only HTTP or HTTPS traffic. When true, Ngrok only opens the HTTPS endpoint. When false, Ngrok only opens the HTTP endpoint

Full 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 "<h1>Yo</h1>" > /usr/share/nginx/html/index.html'
    $ docker run -d -p 80 --volumes-from www_data --name www nginx
    $ curl $(docker port www 80)
    <h1>Yo</h1>
    
  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 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)
    

Helper

For common cases you may want to create an alias in your ~/.profile (or ~/.bashrc, ~/.zshrc, or equivalent):

function docker-ngrok() {
  docker run --rm -it --link "$1":http wernight/ngrok ngrok http http:80
}
# For ZSH with Oh-My-Zsh! and 'docker' plugin enabled, you can also enable auto-completion:
#compdef __docker_containers docker-ngrok

Then to run the simple example just do docker-ngrok web_service_container.

For non dockerized http targets consider this helper function:

function expose-ngrok() {
  docker run --rm --net=host -e NGROK_PORT="$1" wernight/ngrok
}

and then visit localhost:4040 for receiving the links.

Feedbacks

Report issues/questions/feature requests on GitHub Issues.

Pull requests are very welcome!

plex-ngrok-docker's People

Contributors

adrienkuhn avatar andriinuts avatar bkuhl avatar ibobo avatar j796160836 avatar mtib avatar sean-e-dietrich avatar senorgeneral avatar wernight avatar zetachang avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

puff0

plex-ngrok-docker's Issues

plex-nfrok failing with "connection refused" error

I'm on the November 26, 2022 version of plex-ngrok in Docker on an UnRaid server. plex-ngrok is failing consistently. It attempts to start then fails out. I've included the log report below. I'm behind CG-NAT and this is the only way I know of to access my Plex server from outside my home network so any help would be appreciated. Thanks!

-Adrian

File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='0.0.0.0', port=4040): Max retries exceeded with url: /api/tunnels (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x154f77787040>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "plexurl.py", line 31, in
print(get_ngrok_url(), flush=True)
File "plexurl.py", line 15, in get_ngrok_url
res = requests.get(url)
File "/usr/lib/python3.8/site-packages/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 565, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=4040): Max retries exceeded with url: /api/tunnels (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x154f77787040>: Failed to establish a new connection: [Errno 111] Connection refused'))
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 95, in create_connection
raise err
File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 85, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/lib/python3.8/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1007, in _send_output
self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 947, in send
self.connect()
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 205, in connect
conn = self._new_conn()
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x14c1e0229040>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='0.0.0.0', port=4040): Max retries exceeded with url: /api/tunnels (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x14c1e0229040>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "plexurl.py", line 31, in
print(get_ngrok_url(), flush=True)
File "plexurl.py", line 15, in get_ngrok_url
res = requests.get(url)
File "/usr/lib/python3.8/site-packages/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 565, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=4040): Max retries exceeded with url: /api/tunnels (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x14c1e0229040>: Failed to establish a new connection: [Errno 111] Connection refused'))
HERE

HTTPS support

I'm having a hard time getting this to work with "Secure connections" set to required. I can get it to update the "Custom server access URLs" but it always lists it as http and not https.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.