连接docker-compose的两个实例 [英] Connect two instances of docker-compose

查看:145
本文介绍了连接docker-compose的两个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用docker-compose运行的服务的dockerized应用程序。我想使用另一个docker-compose应用程序 docker将这个应用程序与ElasticSearch / Logstash / Kibana(ELK)连接-elk 。它们都在开发中的同一台docker机器上运行。在生产中,情况可能并非如此。

I have a dockerized application with a few services running using docker-compose. I'd like to connect this application with ElasticSearch/Logstash/Kibana (ELK) using another docker-compose application, docker-elk. Both of them are running in the same docker machine in development. In production, that will probably not be the case.

如何配置应用程序的 docker-compose.yml 链接到ELK堆栈?

How can I configure my application's docker-compose.yml to link to the ELK stack?

推荐答案

更新2016年6月

以下答案从docker 1.10开始已经过时。有关新解决方案,请参见其他类似的答案。
https://stackoverflow.com/a/34476794/1556338

The answer below is outdated starting with docker 1.10. See this other similar answer for the new solution. https://stackoverflow.com/a/34476794/1556338

旧答案


  1. 创建网络:

  1. Create a network:

 $ docker network create --driver bridge my-net


  • 在docker-compose.yml文件中将该网络作为环境变量( $ {NETWORK} )进行引用。例如:

    pg:
      image: postgres:9.4.4
      container_name: pg
      net: ${NETWORK}
      ports:
        - "5432"
    myapp:
      image: quay.io/myco/myapp
      container_name: myapp
      environment:
        DATABASE_URL: "http://pg:5432"
      net: ${NETWORK}
      ports:
        - "3000:3000"
    


  • 请注意 pg http:// pg:5432 中的内容将解析为pg服务(容器)的IP地址。无需对IP地址进行硬编码; pg的条目会自动添加到myapp容器的/ etc / host中。

    Note that pg in http://pg:5432 will resolve to the ip address of the pg service (container). No need to hardcode ip addresses; An entry for pg is automatically added to the /etc/host of the myapp container.


    1. 调用docker -compose,将创建的网络传递给它:

    1. Call docker-compose, passing it the network you created:

    $ NETWORK=my-net docker-compose up -d -f docker-compose.yml -f other-compose.yml
    


    我创建了一个 桥网络 ,仅在一个节点(主机)内有效。对开发人员有好处。如果需要让两个节点互相通信,则需要创建一个 重叠式网络 。虽然相同的原则。您将网络名称传递给docker-compose up命令。

    I've created a bridge network above which only works within one node (host). Good for dev. If you need to get two nodes to talk to each other, you need to create an overlay network. Same principle though. You pass the network name to the docker-compose up command.

    这篇关于连接docker-compose的两个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆