Connection refused when Gateway and Redis in separate Docker containers


I have 2 containers, one for the gateway and one for Redis, as you can see in the docker-compose.yml file:

    build: .
      - "8101:8080"
      - redis
      - ./tyk.conf:/opt/tyk-gateway/tyk.conf
      - ./apps:/opt/tyk-gateway/apps
      - "host:"

    image: busybox
      - /var/lib/redis

    image: redis:latest
      - "8102:6379"
      - redisdata

When I lift the containers, I get the error:

"Connection to Redis failed, reconnect in 10s" err="dial tcp getsockopt: connection refused"

Here’s the configuration of Tyk (tyk.conf):

  "listen_port": 8080,
  "secret": "<some-secret-that-I-have-hidden-for-the-post>",
  "template_path": "/opt/tyk-gateway/templates",
  "tyk_js_path": "/opt/tyk-gateway/js/tyk.js",
  "use_db_app_configs": false,
  "app_path": "/opt/tyk-gateway/apps",
  "middleware_path": "/opt/tyk-gateway/middleware",
  "storage": {
    "type": "redis",
    "host": "redis",
    "port": 8102,
    "username": "",
    "password": "",
    "database": "2",
    "optimisation_max_idle": 500,
    "optimisation_max_active": 800

I am sure the problem is from the host/IP but I don’t know how to approach the problem. I guess it’s because the gateway is trying to find the Redis instance within its container, instead of going outside, to the host machine, and then connecting to the Redis container…

By looking at the /etc/hosts file of the gateway container I got this info:

So, it sets up Redis to be on that IP… How can I force the gateway too look towards the host machine IP instead?

Any ideas?


Have you configured redis to allow connections from outisde? Redis usually binds to localhost


I updated my OP with a screenshot of the gateway’s container’s hosts file. Maybe that will give you some insight?
And the only configuration I’ve got for Redis is the one you can see in the docker-compose.yml file. :slight_smile:


If I set the extra_hosts of the gateway container as follows:

      - "tykgatewaytest_redis_1 redis:"

Then it seems to connect to Redis successfully, but then I cannot access the Tyk container anymore…


You just need to make sure the redis container is linked to the gateway and dashboard containers.

If you look at your tyk.conf, it says it expects the redis DB to be on the host redis, in your hosts file, I can see a redis listed.

I think if you have more than one image, you might want to use a docker network instead of direct links, take a look at our docker quickstart