I discovered an excellent, tiny Docker image for ngrok: wernight/ngrok
. I am now using it to expose this blog locally during development.
You can find the image on Docker Hub and its source on GitHub (assuming the GitHub link was intended to be the source, if it’s just a mirror of Docker Hub, the Docker Hub link is primary).
Here are some handy snippets for interacting with the ngrok container. Note that while docker-compose port ngrok 4040
can be used to get the port for API calls (e.g., curl $(docker-compose port ngrok 4040)/api/tunnels
), I use $(docker ps -l -q --filter "name=blog_ngrok")
to identify the container ID. This approach works with both docker-compose up/run
and direct docker
commands.
- View Logs:
BLOG=$(docker ps -l -q --filter "name=blog_ngrok")
docker logs -f $BLOG
- Check Open ngrok Tunnels:
BLOG=$(docker ps -l -q --filter "name=blog_ngrok")
curl $(docker port $BLOG 4040)/api/tunnels
- Open Browser with ngrok HTTP Console:
BLOG=$(docker ps -l -q --filter "name=blog_ngrok")
open http://$(docker port $BLOG 4040)
This is how the docker-compose.yml
file looks for this Jekyll site, incorporating the ngrok service:
version: '3'
volumes:
ruby-cache:
driver: local
services:
build:
image: jekyll/jekyll
volumes:
- ruby-cache:/usr/local/bundle
- ./:/srv/jekyll
command: jekyll build
jekyll:
image: jekyll/jekyll
volumes:
- ruby-cache:/usr/local/bundle
- ./:/srv/jekyll
command: jekyll serve --incremental --watch
ports:
- 127.0.0.1:4000:4000
ngrok:
image: wernight/ngrok
links:
- jekyll
stdin_open: true
tty: true
ports:
- 127.0.0.1:4040:4040
environment:
- NGROK_REGION=eu
- NGROK_AUTH=...
- NGROK_SUBDOMAIN=...
- NGROK_PROTOCOL=http
- NGROK_PORT=jekyll:4000