Kafka access inside and outside docker









up vote
2
down vote

favorite












I'm trying to start a kafka service using docker-compose, and it should be able to be accessed inside and outside docker. So, it should be matter of setting the right advertisers inside and outside:



version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9094:9092"
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://127.0.0.1:9094
KAFKA_ADVERTISED_LISTENERS: INSIDE://:9092,OUTSIDE://127.0.0.1:9094
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE


The problem is that when I try to connect from outside the cluster, I don't get 127.0.0.1 as the name of the node, but the internal hostname:



$ kafkacat -L -b 127.0.0.1:9094
Metadata for all topics (from broker -1: 127.0.0.1:9092/bootstrap):
1 brokers:
broker 1001 at 91588ea968d4:9092
28 topics:
...


Isn't the purpose of KAFKA_ADVERTISED_LISTENERS and KAFKA_LISTENERS to handle that situation? I tried setting KAFKA_ADVERTISED_HOST_NAME but it's ignored (one piece of documentation says it's deprecated, other one says that it's still active), but nevertheless that doesn't seem to be the answer, since I want two different advertised hostnames for two different networks.



I guess the old question remains: how to make kafka work inside and outside docker-compose?










share|improve this question























  • Can you link to the two docs you mention that are inconsistent? It would be good to fix them if there is an ambiguity.
    – Robin Moffatt
    Nov 11 at 11:47










  • It's in hub.docker.com/r/wurstmeister/kafka section "listener configuration". It's not kafka documentation, but wurstmeister docker image: " Later versions of Kafka have deprecated advertised.host.name and advertised.port. NOTE: advertised.host.name and advertised.port still work as expected, but should not be used if configuring the listeners."
    – jdinunzio
    Nov 11 at 12:37










  • Ah right. FWIW Confluent have a full set of Kafka images here: hub.docker.com/u/confluentinc
    – Robin Moffatt
    Nov 11 at 12:51














up vote
2
down vote

favorite












I'm trying to start a kafka service using docker-compose, and it should be able to be accessed inside and outside docker. So, it should be matter of setting the right advertisers inside and outside:



version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9094:9092"
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://127.0.0.1:9094
KAFKA_ADVERTISED_LISTENERS: INSIDE://:9092,OUTSIDE://127.0.0.1:9094
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE


The problem is that when I try to connect from outside the cluster, I don't get 127.0.0.1 as the name of the node, but the internal hostname:



$ kafkacat -L -b 127.0.0.1:9094
Metadata for all topics (from broker -1: 127.0.0.1:9092/bootstrap):
1 brokers:
broker 1001 at 91588ea968d4:9092
28 topics:
...


Isn't the purpose of KAFKA_ADVERTISED_LISTENERS and KAFKA_LISTENERS to handle that situation? I tried setting KAFKA_ADVERTISED_HOST_NAME but it's ignored (one piece of documentation says it's deprecated, other one says that it's still active), but nevertheless that doesn't seem to be the answer, since I want two different advertised hostnames for two different networks.



I guess the old question remains: how to make kafka work inside and outside docker-compose?










share|improve this question























  • Can you link to the two docs you mention that are inconsistent? It would be good to fix them if there is an ambiguity.
    – Robin Moffatt
    Nov 11 at 11:47










  • It's in hub.docker.com/r/wurstmeister/kafka section "listener configuration". It's not kafka documentation, but wurstmeister docker image: " Later versions of Kafka have deprecated advertised.host.name and advertised.port. NOTE: advertised.host.name and advertised.port still work as expected, but should not be used if configuring the listeners."
    – jdinunzio
    Nov 11 at 12:37










  • Ah right. FWIW Confluent have a full set of Kafka images here: hub.docker.com/u/confluentinc
    – Robin Moffatt
    Nov 11 at 12:51












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm trying to start a kafka service using docker-compose, and it should be able to be accessed inside and outside docker. So, it should be matter of setting the right advertisers inside and outside:



version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9094:9092"
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://127.0.0.1:9094
KAFKA_ADVERTISED_LISTENERS: INSIDE://:9092,OUTSIDE://127.0.0.1:9094
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE


The problem is that when I try to connect from outside the cluster, I don't get 127.0.0.1 as the name of the node, but the internal hostname:



$ kafkacat -L -b 127.0.0.1:9094
Metadata for all topics (from broker -1: 127.0.0.1:9092/bootstrap):
1 brokers:
broker 1001 at 91588ea968d4:9092
28 topics:
...


Isn't the purpose of KAFKA_ADVERTISED_LISTENERS and KAFKA_LISTENERS to handle that situation? I tried setting KAFKA_ADVERTISED_HOST_NAME but it's ignored (one piece of documentation says it's deprecated, other one says that it's still active), but nevertheless that doesn't seem to be the answer, since I want two different advertised hostnames for two different networks.



I guess the old question remains: how to make kafka work inside and outside docker-compose?










share|improve this question















I'm trying to start a kafka service using docker-compose, and it should be able to be accessed inside and outside docker. So, it should be matter of setting the right advertisers inside and outside:



version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9094:9092"
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://127.0.0.1:9094
KAFKA_ADVERTISED_LISTENERS: INSIDE://:9092,OUTSIDE://127.0.0.1:9094
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE


The problem is that when I try to connect from outside the cluster, I don't get 127.0.0.1 as the name of the node, but the internal hostname:



$ kafkacat -L -b 127.0.0.1:9094
Metadata for all topics (from broker -1: 127.0.0.1:9092/bootstrap):
1 brokers:
broker 1001 at 91588ea968d4:9092
28 topics:
...


Isn't the purpose of KAFKA_ADVERTISED_LISTENERS and KAFKA_LISTENERS to handle that situation? I tried setting KAFKA_ADVERTISED_HOST_NAME but it's ignored (one piece of documentation says it's deprecated, other one says that it's still active), but nevertheless that doesn't seem to be the answer, since I want two different advertised hostnames for two different networks.



I guess the old question remains: how to make kafka work inside and outside docker-compose?







docker apache-kafka docker-compose






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:00









David Maze

8,5182821




8,5182821










asked Nov 11 at 9:53









jdinunzio

551217




551217











  • Can you link to the two docs you mention that are inconsistent? It would be good to fix them if there is an ambiguity.
    – Robin Moffatt
    Nov 11 at 11:47










  • It's in hub.docker.com/r/wurstmeister/kafka section "listener configuration". It's not kafka documentation, but wurstmeister docker image: " Later versions of Kafka have deprecated advertised.host.name and advertised.port. NOTE: advertised.host.name and advertised.port still work as expected, but should not be used if configuring the listeners."
    – jdinunzio
    Nov 11 at 12:37










  • Ah right. FWIW Confluent have a full set of Kafka images here: hub.docker.com/u/confluentinc
    – Robin Moffatt
    Nov 11 at 12:51
















  • Can you link to the two docs you mention that are inconsistent? It would be good to fix them if there is an ambiguity.
    – Robin Moffatt
    Nov 11 at 11:47










  • It's in hub.docker.com/r/wurstmeister/kafka section "listener configuration". It's not kafka documentation, but wurstmeister docker image: " Later versions of Kafka have deprecated advertised.host.name and advertised.port. NOTE: advertised.host.name and advertised.port still work as expected, but should not be used if configuring the listeners."
    – jdinunzio
    Nov 11 at 12:37










  • Ah right. FWIW Confluent have a full set of Kafka images here: hub.docker.com/u/confluentinc
    – Robin Moffatt
    Nov 11 at 12:51















Can you link to the two docs you mention that are inconsistent? It would be good to fix them if there is an ambiguity.
– Robin Moffatt
Nov 11 at 11:47




Can you link to the two docs you mention that are inconsistent? It would be good to fix them if there is an ambiguity.
– Robin Moffatt
Nov 11 at 11:47












It's in hub.docker.com/r/wurstmeister/kafka section "listener configuration". It's not kafka documentation, but wurstmeister docker image: " Later versions of Kafka have deprecated advertised.host.name and advertised.port. NOTE: advertised.host.name and advertised.port still work as expected, but should not be used if configuring the listeners."
– jdinunzio
Nov 11 at 12:37




It's in hub.docker.com/r/wurstmeister/kafka section "listener configuration". It's not kafka documentation, but wurstmeister docker image: " Later versions of Kafka have deprecated advertised.host.name and advertised.port. NOTE: advertised.host.name and advertised.port still work as expected, but should not be used if configuring the listeners."
– jdinunzio
Nov 11 at 12:37












Ah right. FWIW Confluent have a full set of Kafka images here: hub.docker.com/u/confluentinc
– Robin Moffatt
Nov 11 at 12:51




Ah right. FWIW Confluent have a full set of Kafka images here: hub.docker.com/u/confluentinc
– Robin Moffatt
Nov 11 at 12:51












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Your config of the listeners looks correct, the problem is with your Docker Compose:



ports:
- "9094:9092"


You’re mapping 9094 (‘Outside’) back to 9092 (‘Inside’) and thus when you connect you’re connecting to the ‘Inside’ listener. If you remove this line of config then your listener set up should work as intended.



For more info, see http://rmoff.net/2018/08/02/kafka-listeners-explained/






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247553%2fkafka-access-inside-and-outside-docker%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    Your config of the listeners looks correct, the problem is with your Docker Compose:



    ports:
    - "9094:9092"


    You’re mapping 9094 (‘Outside’) back to 9092 (‘Inside’) and thus when you connect you’re connecting to the ‘Inside’ listener. If you remove this line of config then your listener set up should work as intended.



    For more info, see http://rmoff.net/2018/08/02/kafka-listeners-explained/






    share|improve this answer
























      up vote
      2
      down vote



      accepted










      Your config of the listeners looks correct, the problem is with your Docker Compose:



      ports:
      - "9094:9092"


      You’re mapping 9094 (‘Outside’) back to 9092 (‘Inside’) and thus when you connect you’re connecting to the ‘Inside’ listener. If you remove this line of config then your listener set up should work as intended.



      For more info, see http://rmoff.net/2018/08/02/kafka-listeners-explained/






      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        Your config of the listeners looks correct, the problem is with your Docker Compose:



        ports:
        - "9094:9092"


        You’re mapping 9094 (‘Outside’) back to 9092 (‘Inside’) and thus when you connect you’re connecting to the ‘Inside’ listener. If you remove this line of config then your listener set up should work as intended.



        For more info, see http://rmoff.net/2018/08/02/kafka-listeners-explained/






        share|improve this answer












        Your config of the listeners looks correct, the problem is with your Docker Compose:



        ports:
        - "9094:9092"


        You’re mapping 9094 (‘Outside’) back to 9092 (‘Inside’) and thus when you connect you’re connecting to the ‘Inside’ listener. If you remove this line of config then your listener set up should work as intended.



        For more info, see http://rmoff.net/2018/08/02/kafka-listeners-explained/







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 11:46









        Robin Moffatt

        5,8181228




        5,8181228



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247553%2fkafka-access-inside-and-outside-docker%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto