← Blog

Tiny docker image with ngrok

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.

A few snippets for interacting with the ngrok container. 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