The complete ngrok agent for Python, containerized: tunnels for ingress, inspection, and webhooks
50K+

pyngrok gives Python the complete ngrok
agent, with programmatic tunnels for ingress, inspection, webhooks, demos, and
APIs. ngrok is a reverse proxy that opens secure tunnels from public URLs to localhost, and
because pyngrok runs the real agent, you get everything it offers, from traffic policies and OAuth to its web
inspector and request replay, all callable from Python. This repo provides it in pre-built container images on Docker
Hub.
To launch the container into a Python shell, run:
docker run -e NGROK_AUTHTOKEN=$NGROK_AUTHTOKEN -it alexdlaird/pyngrok
If you want to start in a bash shell instead of Python, you can launch the container with:
docker run -e NGROK_AUTHTOKEN=$NGROK_AUTHTOKEN -it alexdlaird/pyngrok /bin/bash
The pyngrok-example-flask repository also includes a
Dockerfile and make commands to run it, if you would like to see a complete example.
ngrok will look for its config file in this container at /root/.config/ngrok/ngrok.yml. If you want to provide a
custom config file, specify a mount to this file when launching the container.
docker run -v ./ngrok.yml:/root/.config/ngrok/ngrok.yml -it alexdlaird/pyngrok
If you want to use ngrok's web inspector, be sure to expose its port. Ensure whatever config file you use
sets web_addr: 0.0.0.0:4040 (the config provisioned in the
pre-built images already does this).
docker run --env-file .env -p 127.0.0.1:4040:4040 -it alexdlaird/pyngrok
Here is an example of how you could instantiate the container with docker-compose.yml, where you also want a given
Python script to run on startup:
services:
ngrok:
image: alexdlaird/pyngrok
env_file: ".env"
command: [ "python", "/root/my-script.py" ]
volumes:
- ./my-script.py:/root/my-script.py
ports:
- "127.0.0.1:4040:4040"
Then launch it with:
docker compose up -d
For more advanced usage of pyngrok, its official documentation is available
on Read the Docs.
The pyngrok package puts the default ngrok binary on your path in the container, so all features of ngrok are
also available on the command line.
docker run -e NGROK_AUTHTOKEN=$NGROK_AUTHTOKEN -it alexdlaird/pyngrok ngrok http 80
For details on how to fully leverage ngrok from the command line,
see ngrok's official documentation.
Images are multi-architectural, and tagged with the following format:
alexdlaird/pyngrok:py$PYTHON_VERSION-$DISTRO-$VERSION
The following tag variants are available:
$PYTHON_VERSION has 3.11 through 3.15
latest$DISTRO has alpine, or Debian flavors of bookworm, slim-bookworm
slim-bookworm$VERSION matches the container version in table below
latestThe first three numbers of the container version correspond to the version of pyngrok it has installed, and you can
just use the pyngrok version to grab the latest tagged image for that release.
This table shows the ngrok version that is published in each image:
| Container Version | Agent Version |
|---|---|
| 9.1.0.0 | 3.39.13 |
| 9.0.3.1 | 3.39.13 |
| 9.0.3.0 | 3.39.13 |
| 9.0.2.0 | 3.39.11 |
| 9.0.1.0 | 3.39.11 |
| 9.0.0.0 | 3.39.11 |
| 8.2.0.0 | 3.39.11 |
| 8.1.2.0 | 3.39.1 |
| 8.1.1.0 | 3.39.0 |
| 8.1.0.0 | 3.38.0 |
| 8.0.0.0 | 3.37.6 |
| 7.5.1.0 | 3.37.1 |
| 7.5.0.1 | 3.36.1 |
| 7.5.0.0 | 3.33.0 |
| 7.4.0.0 | 3.29.0 |
| 7.3.0.1 | 3.26.0 |
| 7.3.0.0 | 3.25.1 |
| 7.2.12.2 | 3.25.0 |
| 7.2.12.1 | 3.24.0 |
| 7.2.12.0 | 3.23.3 |
Content type
Image
Digest
sha256:05b30c7ac…
Size
76 MB
Last updated
3 days ago
docker pull alexdlaird/pyngrok