本文介绍了Docker-compose链接vs external_links的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信这是一个简单的问题,但是我仍然无法从Docker组成的文档中得到它.链接和external_links有什么区别?

I believe it is simple question but I still do not get it from Docker-compose documentations. What is the difference between links and external_links?

我喜欢external_links,因为我想拥有docker-compose核心,并且我想扩展它而不覆盖核心链接.

I like external_links as I want to have core docker-compose and I want to extend it without overriding the core links.

我到底有什么,我正在尝试设置logstash,具体取决于elasticsearch.Elasticsearch位于核心docker-compose中,logstash位于依赖项中.所以我不得不在依赖的docker-compose中定义弹性搜索作为参考,因为logstash需要它作为链接.但是Elasticsearch已经拥有自己的链接,我不想在从属链接中重复它们.

What exactly I have, I am trying to setup logstash which depends on the elasticsearch. Elasticsearch is in the core docker-compose and the logstash is in the depending one. So I had to define the elastic search in the depended docker-compose as a reference as logstash need it as a link. BUT Elasticsearch has already its own links which I do not want to repeat them in the dependent one.

我可以用external_link代替链接吗?

Can I do that with external_link instead of link?

我知道链接会确保链接在链接之前先启动,external_link会执行相同的操作吗?

I know that links will make sure that the link is up first before linking, does the external_link will do the same?

感谢您的帮助.谢谢.

推荐答案

当您要将同一docker-compose.yml中的容器链接在一起时,请使用 links .您需要做的只是将链接设置为服务名称.像这样:

Use links when you want to link together containers within the same docker-compose.yml. All you need to do is set the link to the service name. Like this:

---
elasticsearch:
  image: elasticsearch:latest
  command: elasticsearch -Des.network.host=0.0.0.0
  ports:
    - "9200:9200"

logstash:
  image: logstash:latest
  command: logstash -f logstash.conf
  ports:
    - "5000:5000"
  links:
    - elasticsearch

如果您要将docker-compose.yml内的容器链接到另一个未包含在同一docker-compose.yml内或以其他方式启动的容器,则可以使用 external_links ,然后将链接设置为容器的名称.像这样:

If you want to link a container inside of the docker-compose.yml to another container that was not included in the same docker-compose.yml or started in a different manner then you can use external_links and you would set the link to the container's name. Like this:

---
logstash:
  image: logstash:latest
  command: logstash -f logstash.conf
  ports:
    - "5000:5000"
  external_links:
    - my_elasticsearch_container

除非您的用例出于某种原因要求它们不能位于同一docker-compose.yml中,否则我建议采用第一种方法

I would suggest the first way unless your use case for some reason requires that they cannot be in the same docker-compose.yml

这篇关于Docker-compose链接vs external_links的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 16:46