我正在尝试设置一个docker- compose文件,该文件旨在用Supervisor替换运行多个进程(RQ worker,RQ仪表板和Flask应用程序)的单个Docker容器解决方案。
主机系统是Debian 8 Linux,我的docker-compose.yml样子如下(我删除了所有其他条目以减少错误源):
docker-compose.yml
version: '2' services: redis: image: redis:latest rq-worker1: build: . command: /usr/local/bin/rqworker boo-uploads depends_on: - redis
“ rq-worker1”是Python RQ工作者,尝试通过本地主机和端口6379连接到Redis,但无法建立连接:
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
输出docker ps如下:
docker ps
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
我尝试了针对本地IP 0.0.0.0 /127.0.0.1甚至本地主机运行RQ工作器的所有操作。在Stackoverflow上发布的其他解决方案也对我不起作用(docker-compose:容器之间的连接被拒绝,但是可以从主机访问服务
这是我的docker info输出:
docker info
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
有谁知道为什么两个容器之间的连接不起作用?
在你的代码localhost从rq-worker1为rq- worker1自身,不redis,你不能达到redis:6379通过连接到localhost从rq- worker1。但是默认情况下redis,rq- worker1它们位于同一网络中,您可以在该网络中将服务名用作域名。这意味着您可以redis通过rq- worker1使用redis域名来连接到服务,例如:client.connect(("redis", 6379))
localhost
rq-worker1
rq- worker1
redis
redis:6379
client.connect(("redis", 6379))
此时应更换localhost同redis在的配置rq-worker1。