RabbitMq-在docker

时间:2019-02-12 14:57:08

标签: docker asp.net-core .net-core rabbitmq

我在docker-compose中有以下内容

rabbitmq:
   hostname : rabbit
   image: rabbitmq:3-management
   container_name: rabbitmq
   volumes:
     - rabbitmqdata:/var/lib/rabbitmq
   ports:
     - "15672:15672"
     - "5672:5672"
   environment:
     - RABBITMQ_DEFAULT_USER=rabbitmquser
     - RABBITMQ_DEFAULT_PASS=DEBmbwkSrzy9D1T9cJfa

当我去http://localhost:15672时,可以从Docker容器外部进行管理。另外,当我尝试使用localhost作为主机名从外部连接到Docker容器时,一切都会按预期进行。

问题

当我尝试连接到另一个docker容器中的Rabbit mq docker容器时,根据传递的主机名,我收到以下错误。

我假设自从我使用rabbit将实例命名为hostname : rabbit以来,它实际上可以使用主机名rabbit

运行
rabbit = no device or such address
rabbitmq = no device or such address
localost = Connection refused 127.0.0.1:5672

docker inspect ..
Networks > IpAddress 
192.168.0.2 = The operation has timed out.

编辑:

添加了更多信息以诊断问题,我正在使用调试从Visual Studio运行Rabbitmq和.net核心(使用docker和docker-compose选项) 这是两个容器的网络信息,它们似乎在同一网络上。

RabbitMq

"Networks": {
            "dockercompose2774038413166585699_default": {
                "IPAMConfig": null,
                "Links": null,
                "Aliases": [
                    "ad88529531f6",
                    "rabbitmq"
                ],
                "NetworkID": "eb8be794b07df62dde4c1fe7fe59178cd218c540db65eae2851c55374a3d2aa3",
                "EndpointID": "e4e8c0f147ee417a8c77742ce42f839837cee83d05bfd14af346b9ee614135c2",
                "Gateway": "192.168.16.1",
                "IPAddress": "192.168.16.4",
                "IPPrefixLen": 20,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "02:42:c0:a8:10:04",
                "DriverOpts": null
            }
        }

Web Api应用

"Networks": {
            "dockercompose2774038413166585699_default": {
                "IPAMConfig": null,
                "Links": null,
                "Aliases": [
                    "c977499feba4",
                    "reddit.api"
                ],
                "NetworkID": "eb8be794b07df62dde4c1fe7fe59178cd218c540db65eae2851c55374a3d2aa3",
                "EndpointID": "8dc76a20bb613402b0f3dc95d843d9605711f24543b842c384038b00e025dd4a",
                "Gateway": "192.168.16.1",
                "IPAddress": "192.168.16.3",
                "IPPrefixLen": 20,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "02:42:c0:a8:10:03",
                "DriverOpts": null
            }
        }

Docker Compose

version: '3.4'

services:


  rabbitmq:
    hostname : rabbit
    image: rabbitmq:3-management
    container_name: rabbitmq
    volumes:
      - rabbitmqdata:/var/lib/rabbitmq
    ports:
      - "15672:15672"
      - "5672:5672"
    environment:
      - RABBITMQ_DEFAULT_USER=rabbitmquser
      - RABBITMQ_DEFAULT_PASS=DEBmbwkSrzy9D1T9cJfa

  redis:
    image: redis
    container_name: redis
    hostname: redis
    ports:
      - "6379:6379"

  logserver:
    image: datalust/seq:latest
    container_name: logserver
    ports:
      - "5020:80"
    environment:
      - ACCEPT_EULA=Y 


  reddit.api:
    image: ${DOCKER_REGISTRY-}redditapi
    build:
      context: .
      dockerfile: src/Services/SocialMedia/Reddit/Reddit.API/Dockerfile

  events.api:
    image: ${DOCKER_REGISTRY-}eventsapi
    build:
      context: .
      dockerfile: src/Services/Events/Events.API/Dockerfile


volumes:
  rabbitmqdata:
    external: true

覆盖

version: '3.4'

services:
  reddit.api:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_HTTPS_PORT=44345
    ports:
      - "63346:80"
      - "44345:443"
    volumes:
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
  events.api:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_HTTPS_PORT=44399
    ports:
      - "65428:80"
      - "44399:443"
    volumes:
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro

0 个答案:

没有答案