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

Auth token?

Open jhagege opened this issue 7 years ago • 11 comments

Thanks a lot looks great !!! How can I add an auth token ? I tried docker run ngrok-container ngrok authtoken 'authToken' but it writes me:

t=2016-07-07T14:52:06+0000 lvl=warn msg="failed to get home directory, using $HOME instead" err="user: Current not implemented on linux/amd64" $HOME=/home/ngrok
Failed to save authtoken to configuration file '/home/ngrok/.ngrok2/ngrok.yml': open /home/ngrok/.ngrok2/ngrok.yml: permission denied

jhagege avatar Jul 07 '16 14:07 jhagege

Would it be hard to programatically support changing env variable NGROK_AUTH ?

jhagege avatar Jul 07 '16 14:07 jhagege

Ah thanks I cannot test this but it seems like an easy fix.

Normally the access right should be fine thanks to this line:

chown ngrok:ngrok /home/ngrok

Are you mounting volumes? Running as another user?

wernight avatar Jul 08 '16 07:07 wernight

Thanks for the fast answer.

Here is my Dockerfile: FROM wernight/ngrok:latest ENV NGROK_AUTH 'auth_key' CMD ["ngrok", "start", "--none"]

jhagege avatar Jul 08 '16 08:07 jhagege

If you specify CMD you cannot use environment variables. Updating README. Either using only environment variables, or use only the CMD and put the token in the command-line.

wernight avatar Jul 08 '16 09:07 wernight

Interesting, I would like the service to be started when the container launches, and don't want the users to manually run the command ngrok start --none. Could you think of a workaround for it to work out-of-the box? I tried putting in the CMD the auth key but didn't succeed for some reason...

Thanks a lot for your help!

jhagege avatar Jul 08 '16 09:07 jhagege

NGROK_AUTH does only generate a command-line like:

`ngrok http -authtoken=$TOKEN -log stdout`

wernight avatar Jul 08 '16 10:07 wernight

Now I understand better thanks. Still I would be very glad to be able to set the authtoken programmatically with an ENV variable NGROK_AUTH, because multiple devs are gonna use the same image, and the only change between each would be the auth token...

jhagege avatar Jul 08 '16 10:07 jhagege

Do you think the other docker images of ngrok (including the ones you forked from) could work out for my use case ? Thanks

jhagege avatar Jul 10 '16 05:07 jhagege

I've seen none doing a ngrok start --none. You can just create a Dockerfile and extend this one, or use docker-compose.yml to write your environment.

wernight avatar Jul 11 '16 07:07 wernight

Ah ha! I figure out the problem is. I found the default config file's owner is root, not ngrok user.

/ $ ls -al /home/ngrok/.ngrok2/ngrok.yml
-rw-r--r--    1 root     root            23 Jul  4 07:38 /home/ngrok/.ngrok2/ngrok.yml

that will cause error for ngrok authtoken command

My workaround fix

First, I make a Dockerfile for fix this issue

$ vi Dockerfile

content as follows

FROM wernight/ngrok:latest
USER root
RUN chown -R ngrok:ngrok /home/ngrok/
USER ngrok

(or change it to RUN chown ngrok:ngrok /home/ngrok/.ngrok2/ngrok.yml) Second, build it as new image

$ docker build . -t  j/ngrok:latest

then use it

$ docker run --rm -it j/ngrok sh -c "ngrok authtoken MY_AUTH_TOKEN ; ngrok tcp 12345"

replace MY_AUTH_TOKEN to yours

Maybe I solution is not the best answer, but works.

j796160836 avatar Aug 20 '17 14:08 j796160836

Same shit with ngrok installed from snap on ubuntu 18 laptop:

$ ngrok authtoken <token>
ERROR:  Failed to save authtoken to configuration file '/home/alex/.ngrok2/ngrok.yml': open /home/alex/.ngrok2/ngrok.yml: permission denied

And ok with unzipped one.

sasha-x avatar Aug 25 '19 20:08 sasha-x