Docker-compose links vs external_links

后端 未结 3 794
梦谈多话
梦谈多话 2021-02-14 04:32

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?

I like external_li

相关标签:
3条回答
  • 2021-02-14 05:11

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

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

    0 讨论(0)
  • 2021-02-14 05:19

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

    links waits for container to boot up and get IP address which is used in etc/hosts file, therefore external_link has already IP:hostname values name described in docker-compose file.

    Moreover links will be deprecated

    0 讨论(0)
  • 2021-02-14 05:30

    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
    

    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
    

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

    0 讨论(0)
提交回复
热议问题