Docker-compose: redis connection refused between containers

I am trying to set up a docker build file that is intended to replace a single Docker container solution that runs several processes (RQ worker, RQ dashboard and Flask application) with Supervisor .

The host system is Debian 8 Linux, and my docker-compose.yml looks like this (I deleted all other entries to reduce the sources of errors):

 version: '2' services: redis: image: redis:latest rq-worker1: build: . command: /usr/local/bin/rqworker boo-uploads depends_on: - redis 

"rq-worker1" is a Python RQ worker trying to connect to redis via localhost and port 6379, but it cannot establish a connection:

 redis_1 | 1:M 23 Dec 13:06:26.285 * The server is now ready to accept connections on port 6379 rq-worker1_1 | [2016-12-23 13:06] DEBUG: worker: Registering birth of worker d5cb16062fc0.1 rq-worker1_1 | Error 111 connecting to localhost:6379. Connection refused. galileoqueue_rq-worker1_1 exited with code 1 

The output of docker ps as follows:

 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 36cac91670d2 redis:latest "docker-entrypoint.sh" 14 minutes ago Up About a minute 6379/tcp galileoqueue_redis_1 

I tried everything: from running a working RQ from local IPs 0.0.0.0/127.0.0.1 and even from localhost. Other solutions published in Stackoverflow also did not work for me ( docker-compose: the connection was refused between containers, but access to the service was from a host , for example.).

And this is my docker info output:

 Containers: 25 Running: 1 Paused: 0 Stopped: 24 Images: 485 Server Version: 1.12.5 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 436 Dirperm1 Supported: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: null bridge host overlay Swarm: inactive Runtimes: runc Default Runtime: runc Security Options: Kernel Version: 3.16.0-4-amd64 Operating System: Debian GNU/Linux 8 (jessie) OSType: linux Architecture: x86_64 CPUs: 8 Total Memory: 13.61 GiB Name: gp-pc-201 ID: LBGV:K26G:UXXI:BWRH:OYVE:OQTA:N7LQ:I4DV:BTNH:FZEW:7XDD:WOCU 

Does anyone have an idea why the connection between the two containers is not working?

+6
source share
1 answer

Your localhost code from rq-worker1 has rq-worker1 , not redis , and you cannot reach redis:6379 by connecting to localhost from rq-worker1 . But by default, redis and rq-worker1 are on the same network , and you can use the service name as the domain name on this network. This means that you can connect to the redis service from rq-worker1 using redis as the domain name, for example: client.connect(("redis", 6379))

You must replace localhost with redis in the rq-worker1 .

+6
source

Source: https://habr.com/ru/post/1013469/


All Articles