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

cannot connect into redis through localhost connection #3

Closed
fajarmuslim opened this issue Apr 5, 2023 · 3 comments
Closed

cannot connect into redis through localhost connection #3

fajarmuslim opened this issue Apr 5, 2023 · 3 comments

Comments

@fajarmuslim
Copy link

fajarmuslim commented Apr 5, 2023

Hi, I just learned nomad from the nomad website to follow the getting started tutorial there.

When, I tried to running the example script there. There are error happened because nomad job services (web) cannot reach into another nomad job services (redis).

I believe, it is because of the network on docker side. But, it still cannot figure out what actually happened inside nomad...

I successfully accessed the redis connection from the local machine through local host address and port.

but, another nomad job (web) can't connect through the local host and port.

here is the log
2023-04-05 16:37:13 * Serving Flask app 'webviewer'
2023-04-05 16:37:13 * Debug mode: off
2023-04-05 16:37:13 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
2023-04-05 16:37:13 * Running on all addresses (0.0.0.0)
2023-04-05 16:37:13 * Running on http://127.0.0.1:5000
2023-04-05 16:37:13 * Running on http://172.17.0.3:5000
2023-04-05 16:37:13 Press CTRL+C to quit
2023-04-05 16:38:43 [2023-04-05 09:38:43,852] ERROR in app: Exception on / [GET]
2023-04-05 16:38:43 Traceback (most recent call last):
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 624, in connect
2023-04-05 16:38:43 sock = self.retry.call_with_retry(
2023-04-05 16:38:43 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/retry.py", line 46, in call_with_retry
2023-04-05 16:38:43 return do()
2023-04-05 16:38:43 ^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 625, in
2023-04-05 16:38:43 lambda: self._connect(), lambda error: self.disconnect(error)
2023-04-05 16:38:43 ^^^^^^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 690, in _connect
2023-04-05 16:38:43 raise err
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 678, in _connect
2023-04-05 16:38:43 sock.connect(socket_address)
2023-04-05 16:38:43 ConnectionRefusedError: [Errno 111] Connection refused
2023-04-05 16:38:43
2023-04-05 16:38:43 During handling of the above exception, another exception occurred:
2023-04-05 16:38:43
2023-04-05 16:38:43 Traceback (most recent call last):
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2525, in wsgi_app
2023-04-05 16:38:43 response = self.full_dispatch_request()
2023-04-05 16:38:43 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1822, in full_dispatch_request
2023-04-05 16:38:43 rv = self.handle_user_exception(e)
2023-04-05 16:38:43 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1820, in full_dispatch_request
2023-04-05 16:38:43 rv = self.dispatch_request()
2023-04-05 16:38:43 ^^^^^^^^^^^^^^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1796, in dispatch_request
2023-04-05 16:38:43 return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
2023-04-05 16:38:43 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/src/app/./webviewer.py", line 62, in home
2023-04-05 16:38:43 return render_template("index.html", stats=stats(), refresh_interval=refresh_interval)
2023-04-05 16:38:43 ^^^^^^^
2023-04-05 16:38:43 File "/usr/src/app/./webviewer.py", line 67, in stats
2023-04-05 16:38:43 for key in r.scan_iter("*"):
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/commands/core.py", line 3003, in scan_iter
2023-04-05 16:38:43 cursor, data = self.scan(
2023-04-05 16:38:43 ^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/commands/core.py", line 2978, in scan
2023-04-05 16:38:43 return self.execute_command("SCAN", *pieces, **kwargs)
2023-04-05 16:38:43 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/client.py", line 1255, in execute_command
2023-04-05 16:38:43 conn = self.connection or pool.get_connection(command_name, **options)
2023-04-05 16:38:43 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 1427, in get_connection
2023-04-05 16:38:43 connection.connect()
2023-04-05 16:38:43 File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 630, in connect
2023-04-05 16:38:43 raise ConnectionError(self._error_message(e))
2023-04-05 16:38:43 redis.exceptions.ConnectionError: Error 111 connecting to 127.0.0.1:31017. Connection refused.
2023-04-05 16:38:43 172.17.0.1 - - [05/Apr/2023 09:38:43] "GET / HTTP/1.1" 500 -

@DenisKnezBeforeNine
Copy link

@fajarmuslim This issue can be resolved with this Pull request but for me at least I'm still not able to connect to the UI from the web service. But this resolves the web not being able to connect to redis

@fajarmuslim
Copy link
Author

@fajarmuslim This issue can be resolved with this Pull request but for me at least I'm still not able to connect to the UI from the web service. But this resolves the web not being able to connect to redis

thanks for the reply @DenisKnezBeforeNine , I had tried the solution there. The localhost cannot be reached. The reason is on mac I use the docker desktop that use different kernel with the macOS kernel. It is separated with the host kernel.

as written here: https://stackoverflow.com/questions/55851632/docker-compose-network-mode-host-not-working

so, on mac we use bridge network instead of host network

the solution is connecting through the host.docker.internal on the configuration

@DzmitryZaitsauIG
Copy link

I've managed to make both the tutorial system and UI access work on MacOS with
the latest Docker Desktop v. 4.36.0, "Enable host networking" option enabled, and the PR #2 applied.
Nomad still uses IPv6 but the tutorial UI is available by localhost:5000

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

3 participants