无法在 Docker 容器中调用 nameko shell

Can't invoke nameko shell within Docker container

我在示例服务的 docker 容器中调用 nameko shell,但收到此错误。我已经设置了两个容器。我的 rabbitmq 容器和我的服务容器。我正在从服务容器 bash 内部调用 nameko shell。容器正确启动,服务容器连接成功。但是我不能使用 shell.

错误

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/amqp/transport.py", line 138, in _connect
    host, port, family, socket.SOCK_STREAM, SOL_TCP)
  File "/usr/local/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -9] Address family for hostname not supported

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/nameko", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/nameko/cli/main.py", line 112, in main
    args.main(args)
  File "/usr/local/lib/python3.6/site-packages/nameko/cli/commands.py", line 143, in main
    main(args)
  File "/usr/local/lib/python3.6/site-packages/nameko/cli/shell.py", line 98, in main
    ctx['n'] = make_nameko_helper(config)
  File "/usr/local/lib/python3.6/site-packages/nameko/cli/shell.py", line 73, in make_nameko_helper
    module.rpc = proxy.start()
  File "/usr/local/lib/python3.6/site-packages/nameko/standalone/rpc.py", line 228, in start
    self._reply_listener.setup()
  File "/usr/local/lib/python3.6/site-packages/nameko/rpc.py", line 260, in setup
    self.queue_consumer.register_provider(self)
  File "/usr/local/lib/python3.6/site-packages/nameko/standalone/rpc.py", line 123, in register_provider
    self._setup_consumer()
  File "/usr/local/lib/python3.6/site-packages/nameko/standalone/rpc.py", line 102, in _setup_consumer
    channel = self.connection.channel()
  File "/usr/local/lib/python3.6/site-packages/kombu/connection.py", line 289, in channel
    chan = self.transport.create_channel(self.connection)
  File "/usr/local/lib/python3.6/site-packages/kombu/connection.py", line 867, in connection
    max_retries=1, reraise_as_library_errors=False
  File "/usr/local/lib/python3.6/site-packages/kombu/connection.py", line 445, in _ensure_connection
    callback, timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/kombu/utils/functional.py", line 344, in retry_over_time
    return fun(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/kombu/connection.py", line 874, in _connection_factory
    self._connection = self._establish_connection()
  File "/usr/local/lib/python3.6/site-packages/kombu/connection.py", line 809, in _establish_connection
    conn = self.transport.establish_connection()
  File "/usr/local/lib/python3.6/site-packages/kombu/transport/pyamqp.py", line 130, in establish_connection
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/amqp/connection.py", line 314, in connect
    self.transport.connect()
  File "/usr/local/lib/python3.6/site-packages/amqp/transport.py", line 78, in connect
    self._connect(self.host, self.port, self.connect_timeout)
  File "/usr/local/lib/python3.6/site-packages/amqp/transport.py", line 149, in _connect
    "failed to resolve broker hostname"))
  File "/usr/local/lib/python3.6/site-packages/amqp/transport.py", line 162, in _connect
    self.sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Docker 文件

FROM python:3-onbuild
CMD ["nameko", "run", "--config", "conf.yml", "helloworld"]

配置文件

AMQP_URI: 'pyamqp://guest:guest@rabbitmq'

docker-编写文件

version: '2'
services:
  echo:
    build: ./echo
    restart: always
    volumes:
     - .:/echo/code
    depends_on:
     - rabbitmq
  rabbitmq:
    image: "rabbitmq"
    ports:
      - "15673:15672"

一段时间后我发现这是我自己的愚蠢错误。我忘记在 nameko shell 命令中添加配置文件。执行 nameko shell 时必须指定消息代理。就我而言,我需要 运行 nameko shell --config config.yml。这使我能够连接并测试我的 nameko 服务。