Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an example for docker compose #26

Open
russorat opened this issue Feb 21, 2023 · 7 comments
Open

add an example for docker compose #26

russorat opened this issue Feb 21, 2023 · 7 comments
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@russorat
Copy link

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

@russorat russorat added documentation Improvements or additions to documentation help wanted Extra attention is needed labels Feb 21, 2023
@Jawabiscuit
Copy link

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?

@russorat
Copy link
Author

@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?

@Jawabiscuit
Copy link

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.

@kunimasu
Copy link

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.

@Jawabiscuit
Copy link

Jawabiscuit commented May 19, 2023

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!

@chinmaypurav
Copy link

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

@philsv
Copy link

philsv commented Mar 28, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants