Adwaith R Krishna
Adwaith R Krishna

Reputation: 892

Running Ngrok in a container using docker

[https://github.com/gtriggiano/ngrok-tunnel ] runs ngrok inside a container. Ngrok is required to run in the container to avert security risks. But am facing problems after running the scripts, which generates the url

$ docker pull gtriggiano/ngrok-tunnel


$ docker run -it  -e "TARGET_HOST=localhost" -e "TARGET_PORT=3000" -p 4040 gtriggiano/ngrok-tunnel

enter image description here am running my rails app on localhost:3000

is it my problem or can it be fixed by altering the scripts(inside the repo)?

Upvotes: 17

Views: 35999

Answers (5)

BT643
BT643

Reputation: 3845

I have started receiving the following error with this now, so this answer may not work for you any more: Your ngrok-agent version "2.3.29" is too old. The minimum supported agent version for your account is "2.3.35". Please update to a newer version with ngrok update, by downloading from https://ngrok.com/download, or by updating your SDK version.


I couldn't get this working but switched to https://github.com/shkoliar/docker-ngrok and it works brilliantly.

In my case I added it to my docker-compose.yml file:

ngrok:
    image: shkoliar/ngrok:latest
    ports:
      - 4551:4551
    links:
      - web
    environment:
      - PARAMS=http -region=eu -authtoken=${NGROK_AUTH_TOKEN} localdev.docker:80
    networks:
      dev_net:
        ipv4_address: 10.5.0.10

And it's started with everything else when I do docker-compose up -d

Then there's a web UI at http://localhost:4551/ for you to see the status, requests, the ngrok URLs, etc.

The Github page does have examples of running it manually from the command line too though, rather than via docker-compose:

Command-line Example The example below assumes that you have running web server docker container named dev_web_1 with exposed port 80.

docker run --rm -it --link dev_web_1 shkoliar/ngrok ngrok http dev_web_1:80

With command line usage, ngrok session is active until it won't be terminated by Ctrl+C combination.

Upvotes: 5

mevsme
mevsme

Reputation: 559

Actually to make ngrok work with your docker container you can install it outside of your project just like the manual on their website says. And then add

  nginx:
    labels:
    - "traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`${PROJECT_BASE_URL}`, `aaa-abc-xxx-140-177.eu.ngrok.io`)"

This particular example is for docker4drupal docker-compose file and traefik mapped as 80:80

Upvotes: 0

Valentino
Valentino

Reputation: 542

this composer works for me. Note that in the entrypoint command for ngrok you have to reference the other service by name

version: '3'
services: 
          
    yourwebserver:
        build:
            context: ./
            dockerfile: ...
            target: ...
        container_name: yourwebserver
        volumes:
            - ...
        ports:
            - ...
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        depends_on: 
            - ngrok

            
    ngrok:
        image: ngrok/ngrok:alpine
        environment:
            NGROK_AUTHTOKEN: '...'
        command: 'http yourwebserver:80'        
        ports:
            - '4040:4040'
        expose:
            - '4040'

Upvotes: 2

Matheus
Matheus

Reputation: 83

I'm not sure if you have already solved this but when I was getting this error I could only solve it like this:

# docker-compose.yml

networks:
  - development

I also needed to expose the 3000 port of my web container because it still wasn't exposed.

# docker.compose.yml

web:
  expose:
    - "3000"

My container for the server running on development is also under the development network. The only parameters, I believe, you should pass for the container to execute are image, ports, environment with DOMAIN and PORT for the server container, a link, and an expose on your web container:

# docker-compose.yml

  ngrok:
    image: shkoliar/ngrok
    ports:
      - 4551:4551
    links:
      - web
    networks:
      - development
    environment:
      - DOMAIN=squad_web
      - PORT=3000

Upvotes: 0

v_sukt
v_sukt

Reputation: 1442

No. if you execute -p with single number it's container port - host port is randomly assigned. Using -p, --publish ip:[hostPort]:containerPort at docker run can specify the the host port with the container port.

as of now the 4040 of container is exposed. Not sure if your service listens by default on it.

To get localhost port execute

docker ps

you'll see the actual port it's not listening on.

CONTAINER ID        IMAGE                     COMMAND             CREATED              STATUS              PORTS                     NAMES
1aaaeffe789d        gtriggiano/ngrok-tunnel   "npm start"         About a minute ago   Up About a minute   0.0.0.0:32768->4040/tcp   wizardly_poincare

here it's listening on localhost:32768

Upvotes: 2

Related Questions