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

non-local API server connection refused when using '-config' #516

Open
bjornbyte opened this issue Jun 20, 2023 · 2 comments
Open

non-local API server connection refused when using '-config' #516

bjornbyte opened this issue Jun 20, 2023 · 2 comments

Comments

@bjornbyte
Copy link

When running toxiproxy server on a remote host with -config and trying to use toxiproxy-cli against it with the --host flag it gets connect: connection refused error.

The content of my config file is

[
  {
    "name": "registry",
    "listen": "[::]:5001",
    "upstream": "10.12.80.149:21146",
    "enabled": true
  }
]

After running with and without the config file, I eventually noticed that when running without, the toxiproxy server log for starting the API server looks like this:

{"level":"info","host":"0.0.0.0","port":"8474","version":"2.5.0","caller":"api.go:119","time":"2023-06-20T19:59:52Z","message":"Starting HTTP server on endpoint 0.0.0.0:8474"}
but when running with config it looks like this
{"level":"info","host":"localhost","port":"8474","version":"2.5.0","caller":"api.go:119","time":"2023-06-20T19:59:52Z","message":"Starting HTTP server on endpoint localhost:8474"}
with "localhost" rather than "0.0.0.0" and since I'm running toxiproxy-cli with --host http://<host_ip>:8474 (i.e. the host is an IP and not localhost) it refuses the connection.

I'm able to work around it by explicitly running the server with -host 0.0.0.0, but find it odd that the listen host would be different depending on if a config is used or not (actually, I suspect the act of creating proxies before the API server starts is what actually impacts it, based on a quick read of the code).

@cgoguyer
Copy link

cgoguyer commented Nov 7, 2023

Hi,I have the same issue with docker.
As @bjornbyte said, it works when adding -host 0.0.0.0!

@denisko
Copy link

denisko commented Sep 3, 2024

I have found that the following setup creates a working setup in a docker-compose file:

toxiproxy:
    image: ghcr.io/shopify/toxiproxy
    container_name: toxiproxy
    command: ["-host=0.0.0.0", "-config=/data/toxiproxy.json"]
    entrypoint: "/toxiproxy"
    volumes:
      - ./docker/toxiproxy/toxiproxy.json:/data/toxiproxy.json
    ports:
      - "8474:8474"

The reason is that if you add only the -config parameter in the command, it overrides the -host parameter this is set in the docker image. With docker inspect you can see these default settings in the docker image:

...
"Config" : {
    ...
    "Cmd" : [ "-host=0.0.0.0" ],
    "Domainname" : "",
    "Entrypoint" : [ "/toxiproxy" ],
    "Env" : [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "LOG_LEVEL=info" ],
    "ExposedPorts" : {
      "8474/tcp" : { }
    },
...

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