Using ngrok with Docker
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:
docker run --net=host -it -e NGROK_AUTHTOKEN=xyz ngrok/ngrok:latest http 80
Note: for MacOS or Windows users, the
--net=host option will not work. You will need to use the special url
host.docker.internal as described in the Docker networking documentation.
docker run -it -e NGROK_AUTHTOKEN=xyz ngrok/ngrok:latest http host.docker.internal:80
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.