title: Docker-compose, Laravel-echo-server and Redis connectivity issue: [ioredis] Unhandled error event: Error: connect ECONNREFUSED 172.20.0.2:6379
body: <p>I'm setting up a docker stack with PHP, PostgreSQL, Nginx, Laravel-Echo-Server and Redis and having some issues with Redis and the echo-server connecting. I'm using a docker-compose.yml:</p>
  
  <pre><code>version: '3'
  
  networks:
    app-tier:
      driver: bridge
  services:
    app:
      build:
        context: .
        dockerfile: .docker/php/Dockerfile
      networks:
        - app-tier
      ports:
        - 9002:9000
      volumes:
        - .:/srv/app
    nginx:
      build:
        context: .
        dockerfile: .docker/nginx/Dockerfile
      networks:
        - app-tier
      ports:
        - 8080:80
      volumes:
        - ./public:/srv/app/public
    db:
      build:
        context: .docker/postgres/
        dockerfile: Dockerfile
      restart: unless-stopped
      networks:
        - app-tier
      ports:
        - 5433:5432
      environment:
        POSTGRES_USER: user
        POSTGRES_PASSWORD: secret
      volumes:
        - .docker/postgres/data:/var/lib/postgresql/data
    laravel-echo-server:
      build:
        context: .docker/laravel-echo-server
        dockerfile: Dockerfile
      restart: unless-stopped
      networks:
        - app-tier
      ports:
        - 6001:6001
      links:
        - 'redis:redis'
    redis:
      build:
        context: .docker/redis
        dockerfile: Dockerfile
      restart: unless-stopped
      networks:
        - app-tier
      volumes:
        - .docker/redis/data:/var/lib/redis/data
  </code></pre>
  
  <p>My echo-server Dockerfile:</p>
  
  <pre><code>FROM node:10-alpine
  
  RUN mkdir -p /usr/src/app
  WORKDIR /usr/src/app
  
  COPY package.json /usr/src/app/
  
  RUN apk add --update \
      python \
      python-dev \
      py-pip \
      build-base
  
  RUN npm install
  
  COPY laravel-echo-server.json /usr/src/app/laravel-echo-server.json
  
  EXPOSE 3000
  CMD [ "npm", "start" ]
  </code></pre>
  
  <p>Redis Dockerfile:</p>
  
  <pre><code>FROM redis:latest
  
  LABEL maintainer="maintainer"
  
  COPY . /usr/src/app
  COPY redis.conf /usr/src/app/redis/redis.conf
  
  VOLUME /data
  
  EXPOSE 6379
  
  CMD ["redis-server", "/usr/src/app/redis/redis.conf"]
  </code></pre>
  
  <p>My laravel-echo-server.json:</p>
  
  <pre><code>{
      "authHost": "localhost",
      "authEndpoint": "/broadcasting/auth",
      "clients": [],
      "database": "redis",
      "databaseConfig": {
          "redis": {
              "port": "6379",
              "host": "redis"
          }
      },
      "devMode": true,
      "host": null,
      "port": "6001",
      "protocol": "http",
      "socketio": {},
      "sslCertPath": "",
      "sslKeyPath": ""
  }
  </code></pre>
  
  <p>The redis.conf is the default right now. The error I am getting from the laravel-echo-server is: </p>
  
  <pre><code>[ioredis] Unhandled error event: Error: connect ECONNREFUSED 172.20.0.2:6379 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1163:14)
  </code></pre>
  
  <p>Redis is up and running fine, using the configuration file and ready to accept connections. <code>docker ps</code> shows both redis and echo-server are up, so they're just not connecting as the error indicates. If I change the final line in the Redis Dockerfile to just <code>CMD ["redis-server"]</code> it appears to connect and auto uses the default config (which is the same as the one I have in my .docker directory), but I get this error: <code>Possible SECURITY ATTACK detected. It looks like somebody is sending POST or Host: commands to Redis. This is likely due to an attacker attempting to use Cross Protocol Scripting to compromise your Redis instance. Connection aborted.</code></p>