Communicate between two asp.net services with docker on same host





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I'm currently trying to host two of my asp.net core services in docker. I am able to get them both up and running but the problem is that I don't know how to communicate between the two containers.



I'm using docker-compose to get my applications up and running and to allocate the ports on my host machine.



The urls to the services are placed in the appsettings.json. I think the problem lies here because I don't know where to get the right IP of the running containers.



I already tried to use the host network in both docker-compose files but I wasn't able to get that working.



I also tried to get the container's IP by using docker container inspect. but those IP's are unreachable.



docker-compose of service 1:



version: '3.4'    
services:
leave.api:
build:
context: .
dockerfile: app1/Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- 5002:5002


docker-compose of service 2:



version: '3.4'
services:
backoffice:
build:
context: .
dockerfile: BackOffice/Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- 5001:5001


I hope to find a way to be able to communicate between the two services.










share|improve this question































    2















    I'm currently trying to host two of my asp.net core services in docker. I am able to get them both up and running but the problem is that I don't know how to communicate between the two containers.



    I'm using docker-compose to get my applications up and running and to allocate the ports on my host machine.



    The urls to the services are placed in the appsettings.json. I think the problem lies here because I don't know where to get the right IP of the running containers.



    I already tried to use the host network in both docker-compose files but I wasn't able to get that working.



    I also tried to get the container's IP by using docker container inspect. but those IP's are unreachable.



    docker-compose of service 1:



    version: '3.4'    
    services:
    leave.api:
    build:
    context: .
    dockerfile: app1/Dockerfile
    environment:
    - ASPNETCORE_ENVIRONMENT=Development
    ports:
    - 5002:5002


    docker-compose of service 2:



    version: '3.4'
    services:
    backoffice:
    build:
    context: .
    dockerfile: BackOffice/Dockerfile
    environment:
    - ASPNETCORE_ENVIRONMENT=Development
    ports:
    - 5001:5001


    I hope to find a way to be able to communicate between the two services.










    share|improve this question



























      2












      2








      2








      I'm currently trying to host two of my asp.net core services in docker. I am able to get them both up and running but the problem is that I don't know how to communicate between the two containers.



      I'm using docker-compose to get my applications up and running and to allocate the ports on my host machine.



      The urls to the services are placed in the appsettings.json. I think the problem lies here because I don't know where to get the right IP of the running containers.



      I already tried to use the host network in both docker-compose files but I wasn't able to get that working.



      I also tried to get the container's IP by using docker container inspect. but those IP's are unreachable.



      docker-compose of service 1:



      version: '3.4'    
      services:
      leave.api:
      build:
      context: .
      dockerfile: app1/Dockerfile
      environment:
      - ASPNETCORE_ENVIRONMENT=Development
      ports:
      - 5002:5002


      docker-compose of service 2:



      version: '3.4'
      services:
      backoffice:
      build:
      context: .
      dockerfile: BackOffice/Dockerfile
      environment:
      - ASPNETCORE_ENVIRONMENT=Development
      ports:
      - 5001:5001


      I hope to find a way to be able to communicate between the two services.










      share|improve this question
















      I'm currently trying to host two of my asp.net core services in docker. I am able to get them both up and running but the problem is that I don't know how to communicate between the two containers.



      I'm using docker-compose to get my applications up and running and to allocate the ports on my host machine.



      The urls to the services are placed in the appsettings.json. I think the problem lies here because I don't know where to get the right IP of the running containers.



      I already tried to use the host network in both docker-compose files but I wasn't able to get that working.



      I also tried to get the container's IP by using docker container inspect. but those IP's are unreachable.



      docker-compose of service 1:



      version: '3.4'    
      services:
      leave.api:
      build:
      context: .
      dockerfile: app1/Dockerfile
      environment:
      - ASPNETCORE_ENVIRONMENT=Development
      ports:
      - 5002:5002


      docker-compose of service 2:



      version: '3.4'
      services:
      backoffice:
      build:
      context: .
      dockerfile: BackOffice/Dockerfile
      environment:
      - ASPNETCORE_ENVIRONMENT=Development
      ports:
      - 5001:5001


      I hope to find a way to be able to communicate between the two services.







      asp.net docker docker-compose






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 4 at 10:31









      Bernard Vander Beken

      2,76153358




      2,76153358










      asked Jan 4 at 10:28









      R.hagensR.hagens

      11012




      11012
























          4 Answers
          4






          active

          oldest

          votes


















          0














          You could use external_links options, seems the most fit solution in your case:
          https://docs.docker.com/compose/compose-file/#external_links






          share|improve this answer































            0














            This explains bridging containers https://docs.docker.com/v17.09/engine/userguide/networking/default_network/container-communication/



            If your communication is http based I would recommend having a http gateway that keeps track of your containers and their service endpoints.






            share|improve this answer































              0














              You can communicate between two services in docker container using the name of service.



              In your case, you have backoffice and leave.api services in your docker composed file.



              So, you can access the backoffice service from leave.api using https://backoffice:5001/.






              share|improve this answer































                0














                Thanks for all the answers, but I found another solution that works best for my situation.



                I added the following line to both of my docker-compose files:



                network_mode: bridge


                This way both of my containers use the same network. After that I could communicate between the containes using my host ip address with the port the service is bound to. I placed this IP in the appsettings.json the same way as I had it before.






                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',
                  autoActivateHeartbeat: false,
                  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%2f54037132%2fcommunicate-between-two-asp-net-services-with-docker-on-same-host%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  0














                  You could use external_links options, seems the most fit solution in your case:
                  https://docs.docker.com/compose/compose-file/#external_links






                  share|improve this answer




























                    0














                    You could use external_links options, seems the most fit solution in your case:
                    https://docs.docker.com/compose/compose-file/#external_links






                    share|improve this answer


























                      0












                      0








                      0







                      You could use external_links options, seems the most fit solution in your case:
                      https://docs.docker.com/compose/compose-file/#external_links






                      share|improve this answer













                      You could use external_links options, seems the most fit solution in your case:
                      https://docs.docker.com/compose/compose-file/#external_links







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 4 at 10:35









                      AtomiX84AtomiX84

                      1129




                      1129

























                          0














                          This explains bridging containers https://docs.docker.com/v17.09/engine/userguide/networking/default_network/container-communication/



                          If your communication is http based I would recommend having a http gateway that keeps track of your containers and their service endpoints.






                          share|improve this answer




























                            0














                            This explains bridging containers https://docs.docker.com/v17.09/engine/userguide/networking/default_network/container-communication/



                            If your communication is http based I would recommend having a http gateway that keeps track of your containers and their service endpoints.






                            share|improve this answer


























                              0












                              0








                              0







                              This explains bridging containers https://docs.docker.com/v17.09/engine/userguide/networking/default_network/container-communication/



                              If your communication is http based I would recommend having a http gateway that keeps track of your containers and their service endpoints.






                              share|improve this answer













                              This explains bridging containers https://docs.docker.com/v17.09/engine/userguide/networking/default_network/container-communication/



                              If your communication is http based I would recommend having a http gateway that keeps track of your containers and their service endpoints.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jan 4 at 10:40









                              Jonas BJonas B

                              2,02811321




                              2,02811321























                                  0














                                  You can communicate between two services in docker container using the name of service.



                                  In your case, you have backoffice and leave.api services in your docker composed file.



                                  So, you can access the backoffice service from leave.api using https://backoffice:5001/.






                                  share|improve this answer




























                                    0














                                    You can communicate between two services in docker container using the name of service.



                                    In your case, you have backoffice and leave.api services in your docker composed file.



                                    So, you can access the backoffice service from leave.api using https://backoffice:5001/.






                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      You can communicate between two services in docker container using the name of service.



                                      In your case, you have backoffice and leave.api services in your docker composed file.



                                      So, you can access the backoffice service from leave.api using https://backoffice:5001/.






                                      share|improve this answer













                                      You can communicate between two services in docker container using the name of service.



                                      In your case, you have backoffice and leave.api services in your docker composed file.



                                      So, you can access the backoffice service from leave.api using https://backoffice:5001/.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jan 4 at 13:51









                                      100mil100mil

                                      848




                                      848























                                          0














                                          Thanks for all the answers, but I found another solution that works best for my situation.



                                          I added the following line to both of my docker-compose files:



                                          network_mode: bridge


                                          This way both of my containers use the same network. After that I could communicate between the containes using my host ip address with the port the service is bound to. I placed this IP in the appsettings.json the same way as I had it before.






                                          share|improve this answer




























                                            0














                                            Thanks for all the answers, but I found another solution that works best for my situation.



                                            I added the following line to both of my docker-compose files:



                                            network_mode: bridge


                                            This way both of my containers use the same network. After that I could communicate between the containes using my host ip address with the port the service is bound to. I placed this IP in the appsettings.json the same way as I had it before.






                                            share|improve this answer


























                                              0












                                              0








                                              0







                                              Thanks for all the answers, but I found another solution that works best for my situation.



                                              I added the following line to both of my docker-compose files:



                                              network_mode: bridge


                                              This way both of my containers use the same network. After that I could communicate between the containes using my host ip address with the port the service is bound to. I placed this IP in the appsettings.json the same way as I had it before.






                                              share|improve this answer













                                              Thanks for all the answers, but I found another solution that works best for my situation.



                                              I added the following line to both of my docker-compose files:



                                              network_mode: bridge


                                              This way both of my containers use the same network. After that I could communicate between the containes using my host ip address with the port the service is bound to. I placed this IP in the appsettings.json the same way as I had it before.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jan 4 at 14:07









                                              R.hagensR.hagens

                                              11012




                                              11012






























                                                  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.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54037132%2fcommunicate-between-two-asp-net-services-with-docker-on-same-host%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







                                                  Popular posts from this blog

                                                  Mossoró

                                                  Error while reading .h5 file using the rhdf5 package in R

                                                  Pushsharp Apns notification error: 'InvalidToken'