명령을 사용하여 rabbitMQ 컨테이너를 생성하고 있습니다.
docker run -d --hostname localhost --name rabbit-tox rabbitmq:3
그리고 이것은 도커 ps -a 출력입니다-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d95830a43d9 rabbitmq:3 "docker-entrypoint..." 6 minutes ago Up 6 minutes 4369/tcp, 5671-5672/tcp, 25672/tcp rabbit-tox
도커 검사 6d95830a43d9 출력-
[
{
"Id": "6d95830a43d90557009a783779442927ca4bf211198f5c4eb420b7bb78b5de08",
"Created": "2020-03-12T15:34:12.661119753Z",
"Path": "docker-entrypoint.sh",
"Args": [
"rabbitmq-server"
],
"State": {
"Status": "running",
"Running": true,
. . .
"EndpointID": "",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "",
"EndpointID": "",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
코드를 사용하여 컨테이너에 연결하려고합니다.
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()
그러나 그것은 오류를 제공합니다-
Traceback (most recent call last):
File "rmqtest.py", line 4, in <module>
connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))
File "/home/mlokur/venv/lib/python3.7/site-packages/pika/adapters/blocking_connection.py", line 359, in __init__
self._impl = self._create_connection(parameters, _impl_class)
File "/home/mlokur/venv/lib/python3.7/site-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError
죄송합니다. 저는 rabbitMQ를 처음 사용합니다. 어떤 도움을 주시면 감사하겠습니다.
감사.
직접 볼 수있는 두 가지 문제가 있습니다.
이것은 Dockerfile
FROM rabbitmq:management
# Define environment variables.
ENV RABBITMQ_DEFAULT_USER user
ENV RABBITMQ_DEFAULT_PASS password
ADD init.sh /init.sh
RUN ["chmod", "+x", "/init.sh"]
EXPOSE 15672
# Define default command
CMD ["/init.sh"]
이것은 init.sh
#!/bin/sh
# Create Rabbitmq user
( sleep 10 ; \
rabbitmqctl add_user user password ; \
rabbitmqctl set_user_tags user administrator ; \
rabbitmqctl set_permissions -p / user ".*" ".*" ".*" ; \
echo "*** User 'user' with password 'password' completed. ***" ; \
echo "*** Log in the WebUI at port 15672 (example: http:/localhost:15672) ***") &
# $@ is used to pass arguments to the rabbitmq-server command.
# For example if you use it like this: docker run -d rabbitmq arg1 arg2,
# it will be as you run in the container rabbitmq-server arg1 arg2
rabbitmq-server $@
놓음 Dockerfile
과를 init.sh
수행 한 후 하나 개의 폴더와 : docker build -t 'my_rabbit' .
-이 이미지를 구축 할 것입니다.
그런 다음 docker run -p5672:5672 -p15672:15672 my_rabbit
5672
-이것은 RabbitMQ가 메시지를 보내는 포트입니다.
15672
-포트 RabbitMQ의 관리 GUI입니다.
로컬 컴퓨터에서 실행하는 경우 다음으로 이동하여 localhost:15672
사용자 이름 : user
및 암호 : password
및 voila를 입력 할 수 있습니다 . 모두 잘 작동합니다!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다