<bdo id='Fo1pA'></bdo><ul id='Fo1pA'></ul>
    1. <legend id='Fo1pA'><style id='Fo1pA'><dir id='Fo1pA'><q id='Fo1pA'></q></dir></style></legend>
    2. <tfoot id='Fo1pA'></tfoot>

        <i id='Fo1pA'><tr id='Fo1pA'><dt id='Fo1pA'><q id='Fo1pA'><span id='Fo1pA'><b id='Fo1pA'><form id='Fo1pA'><ins id='Fo1pA'></ins><ul id='Fo1pA'></ul><sub id='Fo1pA'></sub></form><legend id='Fo1pA'></legend><bdo id='Fo1pA'><pre id='Fo1pA'><center id='Fo1pA'></center></pre></bdo></b><th id='Fo1pA'></th></span></q></dt></tr></i><div id='Fo1pA'><tfoot id='Fo1pA'></tfoot><dl id='Fo1pA'><fieldset id='Fo1pA'></fieldset></dl></div>

        <small id='Fo1pA'></small><noframes id='Fo1pA'>

      1. 使用pika,如何连接运行在docker中的rabbitmq,从docker开始-与外部网络连接?

        时间:2024-08-11
      2. <small id='0RqXz'></small><noframes id='0RqXz'>

        <i id='0RqXz'><tr id='0RqXz'><dt id='0RqXz'><q id='0RqXz'><span id='0RqXz'><b id='0RqXz'><form id='0RqXz'><ins id='0RqXz'></ins><ul id='0RqXz'></ul><sub id='0RqXz'></sub></form><legend id='0RqXz'></legend><bdo id='0RqXz'><pre id='0RqXz'><center id='0RqXz'></center></pre></bdo></b><th id='0RqXz'></th></span></q></dt></tr></i><div id='0RqXz'><tfoot id='0RqXz'></tfoot><dl id='0RqXz'><fieldset id='0RqXz'></fieldset></dl></div>

          <tbody id='0RqXz'></tbody>
            <legend id='0RqXz'><style id='0RqXz'><dir id='0RqXz'><q id='0RqXz'></q></dir></style></legend>

                <tfoot id='0RqXz'></tfoot>
                  <bdo id='0RqXz'></bdo><ul id='0RqXz'></ul>
                • 本文介绍了使用pika,如何连接运行在docker中的rabbitmq,从docker开始-与外部网络连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下docker合成文件:

                  version: '2.3'
                  networks:
                      default: { external: true, name: $NETWORK_NAME } # NETWORK_NAME in .env file is `uv_atp_network`.
                  
                  services:
                      car_parts_segmentor:
                  #        container_name: uv-car-parts-segmentation
                          image: "uv-car-parts-segmentation:latest"
                          ports:
                              - "8080:8080"
                          volumes:
                              - ../../../../uv-car-parts-segmentation/configs:/uveye/configs
                              - /isilon/:/isilon/
                  #            - local_data_folder:local_data_folder
                          command: "--run_service rabbit"
                          runtime: nvidia
                          depends_on:
                            rabbitmq_local:
                              condition: service_started
                          links:
                            - rabbitmq_local
                          restart: always
                  
                  
                      rabbitmq_local:
                          image: 'rabbitmq:3.6-management-alpine'
                          container_name: "rabbitmq"
                          ports:
                            - ${RABBIT_PORT:?unspecified_rabbit_port}:5672
                            - ${RABBIT_MANAGEMENT_PORT:?unspecified_rabbit_management_port}:15672
                  
                  

                  此程序运行时,docker ps显示

                  21400efd6493   uv-car-parts-segmentation:latest                             "python /uveye/app/m…"   5 seconds ago   Up 1 second    0.0.0.0:8080->8080/tcp, :::8080->8080/tcp                                                                                            joint_car_parts_segmentor_1
                  bf4ab8581f1f   rabbitmq:3.6-management-alpine                               "docker-entrypoint.s…"   5 seconds ago   Up 4 seconds   4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp   rabbitmq
                  
                  我要创建到该Rabbitmq的连接。用户:通过是guest:guest

                  我无法执行此操作,在所有情况下,AMQPConnectionError信息都非常贫乏:

                  下面的代码在另一个不相关的容器中运行。

                  connection = pika.BlockingConnection(pika.URLParameters("amqp://guest:guest@rabbitmq/"))
                  connection = pika.BlockingConnection(pika.URLParameters("amqp://guest:guest@localhost/"))
                  

                  还尝试了

                  $ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' rabbitmq
                  172.27.0.2
                  

                  connection = pika.BlockingConnection(pika.URLParameters("amqp://guest:guest@172.27.0.2/")) #
                  

                  还尝试了

                  
                      credentials = pika.credentials.PlainCredentials(
                          username="guest",
                          password="guest"
                      )
                      parameters = pika.ConnectionParameters(
                          host=ip_address, # tried all above options
                          port=5672,
                          credentials=credentials,
                          heartbeat=10,
                      )
                  
                  

                  请注意,容器car_parts_segmentor能够看到容器rabbitmq。两者都由docker-compose启动。


                  我的假设是这与uv_atp_network两个容器都在其中有关,而我正在尝试从网络外部访问该网络内的坞站。

                  这真的是问题所在吗?

                  如果是,如何实现此目标?

                  面向未来-如何从pika获取更多信息性错误?

                  推荐答案

                  正如我怀疑的那样,问题是名称rabbitmq仅存在于网络uv_atp_network中。

                  尝试连接到该网络的代码在其自身的容器中运行,而该容器不在网络中。

                  解决方案connectcurrent container到网络:

                  import socket
                  
                  
                  client = docker.from_env()
                  network_name = "uv_atp_network"
                  atp_container = client.containers.get(socket.gethostname())
                  client.networks.get(network_name).connect(container=atp_container.id)
                  

                  此后,问题中的上述代码将正常工作,因为rabbitmq可以解析。

                  connection = pika.BlockingConnection(pika.URLParameters("amqp://guest:guest@rabbitmq/"))
                  

                  这篇关于使用pika,如何连接运行在docker中的rabbitmq,从docker开始-与外部网络连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:用Pandas.Rolling计算滚动自相关 下一篇:如何从多个进程递增共享计数器?

                  相关文章

                  <tfoot id='V0R1I'></tfoot>
                  • <bdo id='V0R1I'></bdo><ul id='V0R1I'></ul>

                • <legend id='V0R1I'><style id='V0R1I'><dir id='V0R1I'><q id='V0R1I'></q></dir></style></legend>

                • <small id='V0R1I'></small><noframes id='V0R1I'>

                    <i id='V0R1I'><tr id='V0R1I'><dt id='V0R1I'><q id='V0R1I'><span id='V0R1I'><b id='V0R1I'><form id='V0R1I'><ins id='V0R1I'></ins><ul id='V0R1I'></ul><sub id='V0R1I'></sub></form><legend id='V0R1I'></legend><bdo id='V0R1I'><pre id='V0R1I'><center id='V0R1I'></center></pre></bdo></b><th id='V0R1I'></th></span></q></dt></tr></i><div id='V0R1I'><tfoot id='V0R1I'></tfoot><dl id='V0R1I'><fieldset id='V0R1I'></fieldset></dl></div>