Using ngrok with Docker
For detailed instructions on using ngrok with Kubernetes, check out the k8s quickstart.
ngrok provides pre-built docker images for the ngrok Agent with instructions for getting started. An example command for starting a tunnel to port 80
on the host machine looks like this.
Loading…
Note: the Docker version of ngrok follows the same convention as the agent, for example:
Loading…
Basic Usage
The ngrok docker image wraps the ngrok agent executable. Read the documentation for the ngrok agent CLI docs for all commands.
Run an ngrok agent pointed at localhost:80
Loading…
Choose a URL
If you don't choose a URL, ngrok will assign one for you.
Loading…
Add a Traffic Policy
Traffic Policy is a configuration language that offers you the flexibility to filter, match, manage and orchestrate traffic to your endpoints.
Loading…
traffic-policy.yml
Loading…
Run in the background
Loading…
Use a configuration file
Run the ngrok agent with the config file ./ngrok.yml
from the host machine:
Loading…
Pull the ngrok container image
Loading…
Traffic Inspection
Traffic Inspector
Use Traffic Inspector on your ngrok dashboard
Local Web Inspection on localhost:4040 (Legacy)
The agent serves this web interface on port 4040 so you'll need to publish it as well with -p 4040:4040
Loading…
If you are unable to view the web inspection interface typically available at http://localhost:4040
, you may need to map your host port 4040
to port 4040
on the container, for example:
Loading…
Using ngrok with Docker Compose
If you're more comfortable using Docker Compose, you can use the following as a starting point. Copy the contents below into a new file named docker-compose.yaml
, then run docker compose up
in that directory. This Docker compose file assumes that you have an ngrok.yml
file in the same directory with at least one tunnel defined. Check out the ngrok agent config file documentation for help creating a configuration file with a tunnel definition. If you want to use the same configuration file as your local ngrok agent, you can view the location of the default config file using ngrok config check
.
Loading…
If you're defining your tunnels directly in docker-compose.yaml
rather than using an ngrok.yml
file the configuration will look a little different. Your command will be running an ngrok http
command and you'll be using the special url host.docker.internal
as mentioned in the note above. The following is an example of using the ngrok along with the dockersamples/static-site
image.
Loading…