docker-ngrok icon indicating copy to clipboard operation
docker-ngrok copied to clipboard

add an example for docker compose

Open russorat opened this issue 2 years ago • 7 comments

we should have an example of configuring this with docker compose in the readme.

russorat avatar Feb 21 '23 17:02 russorat

I see there is https://ngrok.com/docs/using-ngrok-with/docker/ which has a section for compose, however I'm having a heck of a time trying to network an nginx and ngrok service defined in the same docker-compose.yml.

I don't have any issues running ngrok on the command line outside of docker-container though. Can the doc be updated with a non-trivial use-case?

Jawabiscuit avatar Apr 21 '23 12:04 Jawabiscuit

@Jawabiscuit thanks for commenting here. I added that docker compose example to our docs recently. Can you post what you've tried here and we can debug and add it to the docs?

russorat avatar Apr 21 '23 17:04 russorat

Yeah sure,

My setup:

Windows 10 WSL2 Ubuntu 22.04 Docker Desktop 4.17.1 Docker version 20.10.23 Compose V2

I was attempting to use ngrok to help self-serve Drone for testing out as a CI/CD solution with GitHub. It's a bit experiemental so I'm not hosting it on external infrastructure yet. I had started a docker-compose.yml already with Drone and a Drone runner setup and I saw the example so I thought i'd drop it in and see if it was possible.

After getting 502 errors consistently, I decided to make a simplified use-case.

docker-compose.yml

version: '3'

services:
  ngrok:
    image: ngrok/ngrok:latest
    restart: unless-stopped
    environment:
      NGROK_AUTHTOKEN: ${NGROK_AUTHTOKEN}
    command:
      - "start"
      - "--all"
      - "--config"
      - "/etc/ngrok.yml"
    volumes:
      - ./ngrok.yml:/etc/ngrok.yml
    ports:
      - 4040:4040
    depends_on:
      - nginx
  nginx:
    image: nginx:latest
    ports:
      - 8080:80

ngrok.yml

version: 2
tunnels:
  drone:
    proto: http
    addr: 8080
    hostname: drone.cghijinks.com

I'm using a .env for the NGROK_AUTHTOKEN.

With that setup I run docker-compose up -d. Browsing to http://localhost:8080/ shows that nginx has started up successfully. Browsing to drone.cghijinks.com I see ERR_NGROK_8012 and then to the interface at localhost:4040 I see a 502 Bad Gateway error.

I'm able to use the CLI with no problem either with a custom URL or using the generated ngrok.io one. What's pretty strange is I can't seem to background the CLI, like ngrok http 8080 &, and expect it to work either.

I've searched around the internet and I did come across someone with an earlier homebrew docker image apparently getting good results with docker-compose so I felt convinced it was possible and maybe I'm misunderstanding something or my ISP is getting in the way.

Thanks. Happy to answer any questions.

Jawabiscuit avatar Apr 21 '23 23:04 Jawabiscuit

How about try addr: host.docker.internal:8080 ?

In my case, if I set addr: 8080, 502 Bad Gateway shows me. But host.docker.internal:8080 is working for my case.

kunimasu avatar May 19 '23 05:05 kunimasu

Awesome! That worked, thankyou!

So, literally that setup above with nginx works simply by modifying ngrok.yml, replacing addr: 8080 with addr: host.docker.internal:8080 like @kunimasu suggested. So now you have a simple example!

Jawabiscuit avatar May 19 '23 13:05 Jawabiscuit

https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host

The reason it is failing on addr: 80 because it tried to call port 80 within that ngrok service which is absent.

I am using it on the bridge network.

  • ngrok.yml
authtoken: authtokenxxxxxxxxxxxxxxxx
version: 2
tunnels:
  your_tunnel_name:
    proto: http
    hostname: static-domain.ngrok-free.app
    addr: nginx:80
    
  • docker-compose.yml
services:
  ngrok:
    image: ngrok/ngrok:latest
    networks:
      - bridge
    command: 
      - "start"
      - "--all"
      - "--config"
      - "/etc/ngrok.yml"
    volumes:
      - ./ngrok.yml:/etc/ngrok.yml
    ports:
      - 4040:4040
  nginx:
    image: nginx:stable
    ports:
      - 80:80
      - 443:443
    networks:
      - bridge
    volumes:
      - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - mysql
      - php

chinmaypurav avatar Aug 29 '23 18:08 chinmaypurav

How about try addr: host.docker.internal:8080 ?

In my case, if I set addr: 8080, 502 Bad Gateway shows me. But host.docker.internal:8080 is working for my case.

Tried to figure this out for hours, this fixed this gateway issue for me. Thank you so much kunimasu!

philsv avatar Mar 28 '24 23:03 philsv