Docker-compose links vs external_links

I believe this is a simple question, but I still don't understand it from the Docker documentation. What is the difference between links and external links?

I like external_links, since I want to have a basic docker layout, and I want to extend it without overriding the main links.

What exactly do I have, I'm trying to configure logstash, which depends on the elastics search. Elasticsearch is in the main docker, and logstash is in the dependent. Therefore, I had to define elastic search in the dependent docker composition as a link, since logstash in it is needed as a link. BUT Elasticsearch already has its own links, which I don’t want to repeat in the dependent.

Can I do this using external_link instead of link?

I know that links will ensure that the link is first before linking, will external_link do the same?

Any help is appreciated. Thanks.

+7
docker docker-compose elasticsearch logstash
source share
3 answers

Use links if you want to link containers inside the same docker-compose.yml file. All you have to do is set a 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 

If you want to link the container inside docker-compose.yml with another container that was not included in the same docker-compose.yml file or started in another way, you can use external_links and you must set the link to the container name. Like this:

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

I would suggest the first way if your use case for some reason does not require that they cannot be in the same docker-compose.yml file

+13
source share

I think external_link will not do the same as links in docker-compose up .

links waiting for the container to load and get the IP address that is used in the etc/hosts , so external_link already has the IP name: the host name specified in the docker-compose file.

Moreover, links will become obsolete

0
source share

Here is a link to a Docker-Compose project that uses Elasticsearch, Logstash, and Kibana. You will see that I am using links:

https://github.com/bahaaldine/elasticsearch-paris-accidentology-demo

-2
source share

All Articles