简体   繁体   中英

Understanding Hostname of Containers in docker-compose.yml

I am trying to understand a docker-compose.yml (also shown at the bottom of this post).

Question: confluent:2181 is used the following line

KAFKA_ZOOKEEPER_CONNECT: "confluent:2181"

How was this confluent hostname defined? If I understand hostnames in Docker correctly, the only container hostnames are zookeeper , kafka , rest-proxy and schema-registry .

docker-compose.yml

version: "2"
services:
    zookeeper:
        image: confluent/zookeeper
        ports:
        - "2181:2181"
        environment:
        zk_id: "1"
        network_mode: "host"
    kafka:
        image: confluent/kafka
        depends_on:
        - zookeeper
        ports:
        - "9092:9092"
        environment:
        KAFKA_ZOOKEEPER_CONNECT: "confluent:2181"
        network_mode: "host"
    rest-proxy:
        image: confluent/rest-proxy
        depends_on:
        - zookeeper
        - kafka
        - schema-registry
        ports:
        - "8082:8082"
        environment:
        RP_ZOOKEEPER_CONNECT: "confluent:2181"
        RP_SCHEMA_REGISTRY_URL: "http://confluent:8081"
        network_mode: "host"
    schema-registry:
        image: confluent/schema-registry
        depends_on:
        - kafka
        - zookeeper
        ports:
        - "8081:8081"
        environment:
        SR_KAFKASTORE_CONNECTION_URL: "confluent:2181"
        network_mode: "host"

You're right. According to the docker-compose.yml the services being defined will provide DNS resolution only for zookeeper , kafka , rest-proxy and schema-registry , and not confluent .

However if you take a look at the documenttion from confluentinc they require you to modify your hosts file in your host machine:

Edit your hosts file and add a host entry for the docker machine.

192.168.99.100 confluent

That's why you can use confluent and get name resolution. It doesn't have anything to do with docker or compose.

PS: Beware that you're using deprecated images according to their documentation

Yes, you are right.

According to the README , you were supposed to run confluent firstly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM