Docker 我能';t连接到Rabbitmq服务器端口5672

Docker 我能';t连接到Rabbitmq服务器端口5672,docker,rabbitmq,symfony,Docker,Rabbitmq,Symfony,用这个命令 php bin/console rabbitmq:consumer -w upload_picture 我有这个问题 [ErrorException] stream_socket_client(): unable to connect to tcp://localhost:5672 (Aucune connexion n'a pu etre établie car l'ordinateur cible lÆa expressÚment refusée. 所以我无法连接到服务

用这个命令

php bin/console rabbitmq:consumer -w upload_picture
我有这个问题

 [ErrorException]
stream_socket_client(): unable to connect to tcp://localhost:5672 (Aucune
 connexion n'a pu etre établie car l'ordinateur cible lÆa expressÚment
 refusée.
所以我无法连接到服务器rabbitmq

config.yml

old_sound_rabbit_mq:
connections:
    default:
        host:     'localhost' # hostname and port of the rabbitmq server
        port:     5672
        user:     'guest'
        password: 'guest'
        vhost:    '/'
        lazy:     true # a lazy connection avoids unnecessary connections to the broker on every request
        connection_timeout: 3
        read_write_timeout: 3
        keepalive: false
        heartbeat: 0
producers:
    upload_picture:
        connection:       default # connects to the default connection configured above
        exchange_options: {name: 'upload_picture', type: direct}
consumers:
    upload_picture:
        connection:       default # connects to the default connection configured above
        exchange_options: {name: 'upload_picture', type: direct}
        queue_options:    {name: 'upload_picture'}
        callback:         upload_picture_service # the UploadPictureConsumer defined below
根据你的评论

7c01193b2f74 projecttest_queue "docker-entrypoint..." 24 hours ago Up 5 hours 4369/tcp, 5671/tcp, 25672/tcp, 0.0.0.0:55672->5672/tcp, 0.0.0.0:32768->15672/tcp
项目正在侦听的端口是55672-请参阅
0.0.0.0:55672->5672/tcp


因此,您需要更新php项目以连接到
localhost:55672
,而不仅仅是
localhost:5672

,您可以直接找到需要连接的端口

docker-inspect--format'{(index.NetworkSettings.Ports“5672/tcp”)0.HostPort}}'rabbitmq_容器


有关如何从docker inspect获取特定值的更多详细信息,请参阅。如果您的命令连接到本地主机,则如果主机上的容器未发布端口5672,它将失败。显示
docker端口您的\u rabbitmq\u容器
,这是rabbitmq计算机上的文档,键入
netstat-a
,并确保它正在侦听该端口,而不仅仅是unix套接字。列表中不存在端口5672(netstat-a)使用is命令docker ps 7c01193b2f74 projecttest_队列“docker入口点…”24小时前5小时4369/tcp,5671/tcp,25672/tcp,0.0.0.0:55672->5672/tcp,0.0.0.0:32768->15672/tcp projecttest_queue_1将localhost替换为容器名称(从您的注释中可以看出projecttest_queue),不幸的是55672也存在同样的问题。在这种情况下,请检查rabbitmq服务器正在侦听的IP。如果您提供的
config.yml
来自rabbitmq服务器,则需要将主机更改为
0.0.0
,以便rabbitmq不会侦听
localhost
,因为它将无法从docker容器外部访问