【问题标题】:Multi-host Docker compose application on SwarmSwarm 上的多主机 Docker 组合应用程序
【发布时间】:2015-11-25 11:38:54
【问题描述】:

我有一个简单的撰写文件,其中有三个服务 A、B 和 C。A 和 B 都依赖于 C(即有 links 到 C)。这是docker-compose.yml的简化摘录:

kafka:
  image: spotify/kafka
  environment:
    ADVERTISED_PORT: 9092
  ports:
    - "2181:2181"
    - "9092:9092"
ServiceA:
  image: elsoufy/myimage
  command: ./mycommand -role producer -queue kafka:9092
  ports:
    - "8080"
ServiceB:
  image: elsoufy/myimage
  command: ./mycommand -role consumer -queue kafka:9092

我已经在 AWS 上设置了一个 Docker swarm,并通过 consul key-store 启用了覆盖网络。我一直在努力让它正常工作(我不得不手动将机器的内核升级到linux 3.16)。

我使用的是 Docker 1.9

Client:
 Version:      1.9.0
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   76d6bc9
 Built:        Tue Nov  3 19:20:09 UTC 2015
 OS/Arch:      darwin/amd64

Server:
 Version:      1.9.0
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   76d6bc9
 Built:        Tue Nov  3 19:20:09 UTC 2015
 OS/Arch:      linux/amd64

我可以使用docker-compose up -d 成功启动组合,但是ServiceAServiceB 在多次尝试连接到kafka 后崩溃,因为他们找不到它。当我尝试使用显式 links 并为此应用启用覆盖时 I get an error:

docker-compose --x-networking --x-network-driver=overlay up

links, which are not compatible with Docker networking and will be ignored. Future versions of Docker will not support links - you should remove them for forwards-compatibility.

当我想启用多主机时,我似乎无法使用links!但是,我如何在容器之间运行一个组合应用程序并在 docker swarm 上扩展容器?

【问题讨论】:

  • docker 1.9 中的新网络功能使用共享网络上的 IP 主机发现作为链接的替代。请参阅以下答案:stackoverflow.com/questions/33785804/…
  • 这条消息只是一个警告(不是错误)。我认为它应该在消息上有一个Warning 前缀,对吧?它只是在复制/粘贴中被切断。
  • @dnephin 我没有完整的消息,我在看到问题一天后发布了这个帖子。
  • @MarkO'Connor 感谢您的链接,看起来我已经手动运行了我的容器,那么 compose 是干什么用的?
  • @MarkO'Connor 当我尝试 tomcat 示例时,服务发现工作正常,但是当我尝试使用 zookeeper(使用 docker-compose.yml 运行)和 kafka(手动运行)时,发现确实有效不工作。

标签: amazon-web-services networking docker docker-compose docker-machine


【解决方案1】:

您不再需要明确的链接。网络应链接同一用户定义网络上的所有容器。 Compose 会根据项目名称为您创建一个默认网络。

【讨论】:

    【解决方案2】:

    要表达容器或服务之间的依赖关系,您可以使用docker-compose.yml 文件中的配置选项depends_on,但使用version 2 文件格式。

    所以你的 docker-compose.yml 文件应该看起来像这样:

    version: '2'
    services:
        kafka:
          image: spotify/kafka
          environment:
            ADVERTISED_PORT: 9092
          ports:
            - "2181:2181"
            - "9092:9092"
    
        ServiceA:
          image: elsoufy/myimage
          command: ./mycommand -role producer -queue kafka:9092
          ports:
            - "8080"
          depends_on:
            - kafka    
    
        ServiceB:
          image: elsoufy/myimage
          command: ./mycommand -role consumer -queue kafka:9092
          depends_on:
            - kafka     
    
    networks:
          ...
    

    docker-compose up 将按依赖顺序启动服务。在上面的示例中,kafka 将在ServiceAServiceB 之前启动。

    注意:如果您将version 1 文件格式与links 一起使用,您的应用程序将可以运行,但Swarm 会将所有容器安排在一台主机上,因为links 介于两者之间容器不能跨具有旧网络系统的主机工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 2017-12-11
      相关资源
      最近更新 更多