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

Docker noob here, help? -- could not read file "srh-config/tokens.json": #26

Closed
dBianchii opened this issue May 11, 2024 · 8 comments
Closed

Comments

@dBianchii
Copy link

sudo docker run hiett/serverless-redis-http                                                                                               10:23:01 
Using port 80
Token resolver started

01:23:16.555 [notice] Application srh exited: Srh.start(:normal, []) returned an error: shutdown: failed to start child: :token_resolver
    ** (EXIT) an exception was raised:
        ** (File.Error) could not read file "srh-config/tokens.json": no such file or directory
            (elixir 1.13.4) lib/file.ex:355: File.read!/1
            (srh 0.1.0) lib/srh/auth/token_resolver.ex:56: Srh.Auth.TokenResolver.do_init_load/1
            (srh 0.1.0) lib/srh/auth/token_resolver.ex:27: Srh.Auth.TokenResolver.init/1
            (stdlib 3.17.2.4) gen_server.erl:423: :gen_server.init_it/2
            (stdlib 3.17.2.4) gen_server.erl:390: :gen_server.init_it/6
            (stdlib 3.17.2.4) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
{"Kernel pid terminated",application_controller,"{application_start_failure,srh,{{shutdown,{failed_to_start_child,token_resolver,{#{'__exception__' => true,'__struct__' => 'Elixir.File.Error',action => <<\"read file\">>,path => <<\"srh-config/tokens.json\">>,reason => enoent},[{'Elixir.File','read!',1,[{file,\"lib/file.ex\"},{line,355}]},{'Elixir.Srh.Auth.TokenResolver',do_init_load,1,[{file,\"lib/srh/auth/token_resolver.ex\"},{line,56}]},{'Elixir.Srh.Auth.TokenResolver',init,1,[{file,\"lib/srh/auth/token_resolver.ex\"},{line,27}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,423}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,390}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,226}]}]}}},{'Elixir.Srh',start,[normal,[]]}}}"}

I understand this is just some configuration I haven't done correctly on my part :P

First, I ran this and worked perfectly. SRH server was up:

sudo docker run \
    -it -d -p 8080:80 --name srh \
    -e SRH_MODE=env \
    -e SRH_TOKEN=your_token_here \
    -e SRH_CONNECTION_STRING="redis://localhost:6379" \
    hiett/serverless-redis-http:latest

But, for some reason the SRH server couldn't reach my redis instance running on 127.0.0.1:6379. I thought that maybe changing the connection_string to 127.0.0.1 instead of localhost would fix it. I then killed my running container and tried running the command / image again. But no luck.

Is there a way to configure the server? I'm guessing I need to create this tokens.json but I don't know how.

@hiett
Copy link
Owner

hiett commented May 11, 2024

You shouldn't need a tokens.json file -- the env command will work just fine.
The problem is actually networking. When you put localhost (or 127.0.0.1, same thing), it is looking inside the docker container. It isn't the same localhost as your parent machine.

Not to worry though -- there is an easy fix for this. Assuming you are using Windows or Mac, you can use host.docker.internal as the IP:

sudo docker run \
    -it -d -p 8080:80 --name srh \
    -e SRH_MODE=env \
    -e SRH_TOKEN=your_token_here \
    -e SRH_CONNECTION_STRING="redis://host.docker.internal:6379" \
    hiett/serverless-redis-http:latest

This will automatically resolve to your parent system's private IP, and should do the trick!

@dBianchii
Copy link
Author

So fast to answer. Thanks a lot. I am actually on Linux Ubuntu.

When I try to run this command, or the command listed in the readme, I get this:

sudo docker run \                                                                                                                         10:39:14 
    -it -d -p 8080:80 --name srh \
    -e SRH_MODE=env \
    -e SRH_TOKEN=your_token_here \
    -e SRH_CONNECTION_STRING="redis://host.docker.internal:6379" \
    hiett/serverless-redis-http:latest
docker: Error response from daemon: Conflict. The container name "/srh" is already in use by container "6b44fb4700db981572d6995e2ec3253427667e3961542af66af27f9dbf8b89a1". You have to remove (or rename) that container to be able to reuse that name.

However, sudo docker ps is empty. There aren't any running containers

@hiett
Copy link
Owner

hiett commented May 11, 2024

This is because the the container is likely stopped in the background, but not removed. you can run docker rm srh, that should do the trick.

Linux is a bit different -- you might have issues with host.docker.internal. That is a feature of Docker Desktop specifically, not built into the normal Docker engine.

You can use the static IP 172.17.0.1. This should work on linux and will be bound to the parent machine's IP

@hiett
Copy link
Owner

hiett commented May 11, 2024

(for reference, docker ps -a should show all containers, including stopped ones.)

@dBianchii
Copy link
Author

Thanks so much @hiett. I didn't know about docker ps -a command. I managed to remove the container, and then I ran this command:

sudo docker run \
    -it -d -p 8080:80 --name srh \
    -e SRH_MODE=env \
    -e SRH_TOKEN=your_token_here \
    -e SRH_CONNECTION_STRING="redis://172.17.0.1:6379" \
    hiett/serverless-redis-http:latest

I managed to connect to the SRH server from my Next.JS local instance, but still it cannot connect to the redis server running on the parent machine.
Guess i'll do more digging around to understand how to make the container talk to the parent machine. If you have any other suggestions I could try let me know.

Maybe after I manage to do it, we can have a tutorial settings on README for linux? Just a suggestion

@dBianchii dBianchii reopened this May 12, 2024
@dBianchii
Copy link
Author

Maybe would it work if I ran redis inside the container? So that the connection wouldn't need to leave it...

@hiett
Copy link
Owner

hiett commented May 12, 2024

There is a docker compose example in the readme that will work out-of-the-box on any operating system: https://github.com/hiett/serverless-redis-http?tab=readme-ov-file#via-docker-compose

This is the recommended way to run, and a lot easier (because you can stop and start redis & srh at the same time!)

Closing this issue because it's general docker issues rather than anything specific with SRH

@hiett hiett closed this as completed May 12, 2024
@dBianchii
Copy link
Author

Hey, thanks so much! Much better to use docker-compose. Definitely need to use and feel more confident with docker.

Thanks for creating this repo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants