LoginSignup
13
5

Dockerでngrokを利用する

Last updated at Posted at 2021-01-12

ngrokとは

ngrokは、ローカルホストを外部に公開(トンネル)できる

やりかた

公式のイメージを用いる
docker composeを利用してnginxを公開します

まずはtokenを発行します

以下から登録して発行してください

docker-compose.yml

version: "3.8"

services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - 80:80
    depends_on:
      - app

  ngrok:
    image: ngrok/ngrok:latest
    restart: unless-stopped
    command:
      - "start"
      - "--all"
      - "--config"
      - "/etc/ngrok.yml"
    ports:
      - 4040:4040
    volumes:
      - ./ngrok.yml:/etc/ngrok.yml

docker-composeと同じ階層にngrok.ymlを作成します

ngrok.yml
version: "2"
authtoken: "ここに取得したToken"
tunnels:
  nginx:
    proto: http
    addr: nginx:80 #ここに接続したいサービス
    host_header: rewrite

あとは、起動して、localhost:4040にアクセスするとurlが発行されているのでそれをもちいて確認してください。

その他のオプションはこちらで確認できます。

便利だし、サクッと使えるので助かる...!
LinebotのようなSSL必須の自己証明不可の外部APIをローカルで開発する場合にはすごく役立ちそうです。

13
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
5