简体   繁体   English

无法从Docker容器内部连接到Redis

[英]Unnable to connect to Redis from inside Docker container

When I start Docker container I get 当我启动Docker容器时我得到

OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 6379), [Errno 111] Connect call failed ('127.0.0.1', 6379)

from Python, but this code works fine on the host machine. 从Python,但此代码在主机上可以正常工作。 How to fix this? 如何解决这个问题?

Dockerfile: gist , OS: macOS 10.12 Dockerfile: gist ,操作系统:macOS 10.12

You can only have a single CMD statement. 您只能有一个CMD语句。 To start both redis-server and python inside a single container you'll need to define a script or run a tool like supervisord to manage your processes. 要在单个容器中同时启动redis-serverpython您需要定义一个脚本或运行诸如supervisord类的工具来管理您的进程。 https://docs.docker.com/engine/admin/multi-service_container/ explains some options and also gives examples. https://docs.docker.com/engine/admin/multi-service_container/解释一些选项并提供示例。 In your case I would give the approach with a shell script a try. 在您的情况下,我将尝试使用Shell脚本的方法。 The Phusion base image https://github.com/phusion/baseimage-docker is a more advanced alternative, starting each process via init service, but might be overkill for your use case. Phusion基本映像https://github.com/phusion/baseimage-docker是一种更高级的替代方法,它通过init服务启动每个进程,但是对于您的用例而言可能会显得过时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM