Docker [Errno 111] Connect call failed ('127.0.0.1', 6379)

前端 未结 4 750
[愿得一人]
[愿得一人] 2021-01-06 09:47

I am trying to follow the tutorial here https://channels.readthedocs.io/en/latest/tutorial/part_2.html and check if channel layer can communicate with Redis. The only differ

4条回答
  •  梦毁少年i
    2021-01-06 10:06

    Try changing 127.0.0.1:6379 to redis:6379.

    Although Redis is running, your python container isn't able to communicate with it; this is because it's trying to connect to 127.0.0.1:6379, but from the container's perspective, there's nothing running there. This can be a bit frustrating to debug, but it's a bit easier if you keep in mind that containers get their own network namespace. As a result, python's localhost != redis's localhost != your host machine's localhost.

    Luckily, it's easy to connect containers that are sharing the same bridge, and by default, docker-compose creates a single bridge network and connects all your containers to them, providing the necessary DNS to allow them to discover one another. As a result, container-to-container communication works simply by using the service name.

    As a note, it's possible to run containers in the same namespace, and to run in them in the namespace of the host, via the --net=container: or --net=host flag. This is especially useful for running debugging tools in a container and attaching them to the network namespace of either another container or the host, e.g. using netshoot to see what ports are listening within the container (exposed or not), docker run --rm -it --net container:test_web_1 nicolaka/netshoot netstat -tulpn.

提交回复
热议问题