Can you use multiple “network_mode: service:XXX” instances in docker compose?












0















I've inherited a legacy app that uses redis, mysql and postgresql. The references to 127.0.0.1 and localhost are everywhere.



My compose file looks like this:



version: '3.3'

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.2
ports:
- 9200:9200
mysql:
image: mysql/mysql-server:5.7.24
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: ''
MYSQL_ROOT_HOST: "%"
ports:
- target: 3306
published: 3306
protocol: tcp
mode: host

webapp:
image: ubuntu/xenial
hostname: webapp
privileged: true
ports:
- target: 80
published: 80
mode: host


Reading the docs, it looks like I can only set one network_mode per service, but I'd like to use something like:



  network_mode: service:elasticsearch
network_mode: service:mysql


But this doesn't appear to be possible, unless I'm missing something. Is there a way to handle this? I basically just want localhost:3306 and localhost:9200 to point to each service from within the webapp service.










share|improve this question



























    0















    I've inherited a legacy app that uses redis, mysql and postgresql. The references to 127.0.0.1 and localhost are everywhere.



    My compose file looks like this:



    version: '3.3'

    services:
    elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.2
    ports:
    - 9200:9200
    mysql:
    image: mysql/mysql-server:5.7.24
    environment:
    MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    MYSQL_ROOT_PASSWORD: ''
    MYSQL_ROOT_HOST: "%"
    ports:
    - target: 3306
    published: 3306
    protocol: tcp
    mode: host

    webapp:
    image: ubuntu/xenial
    hostname: webapp
    privileged: true
    ports:
    - target: 80
    published: 80
    mode: host


    Reading the docs, it looks like I can only set one network_mode per service, but I'd like to use something like:



      network_mode: service:elasticsearch
    network_mode: service:mysql


    But this doesn't appear to be possible, unless I'm missing something. Is there a way to handle this? I basically just want localhost:3306 and localhost:9200 to point to each service from within the webapp service.










    share|improve this question

























      0












      0








      0








      I've inherited a legacy app that uses redis, mysql and postgresql. The references to 127.0.0.1 and localhost are everywhere.



      My compose file looks like this:



      version: '3.3'

      services:
      elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:5.2
      ports:
      - 9200:9200
      mysql:
      image: mysql/mysql-server:5.7.24
      environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
      MYSQL_ROOT_PASSWORD: ''
      MYSQL_ROOT_HOST: "%"
      ports:
      - target: 3306
      published: 3306
      protocol: tcp
      mode: host

      webapp:
      image: ubuntu/xenial
      hostname: webapp
      privileged: true
      ports:
      - target: 80
      published: 80
      mode: host


      Reading the docs, it looks like I can only set one network_mode per service, but I'd like to use something like:



        network_mode: service:elasticsearch
      network_mode: service:mysql


      But this doesn't appear to be possible, unless I'm missing something. Is there a way to handle this? I basically just want localhost:3306 and localhost:9200 to point to each service from within the webapp service.










      share|improve this question














      I've inherited a legacy app that uses redis, mysql and postgresql. The references to 127.0.0.1 and localhost are everywhere.



      My compose file looks like this:



      version: '3.3'

      services:
      elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:5.2
      ports:
      - 9200:9200
      mysql:
      image: mysql/mysql-server:5.7.24
      environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
      MYSQL_ROOT_PASSWORD: ''
      MYSQL_ROOT_HOST: "%"
      ports:
      - target: 3306
      published: 3306
      protocol: tcp
      mode: host

      webapp:
      image: ubuntu/xenial
      hostname: webapp
      privileged: true
      ports:
      - target: 80
      published: 80
      mode: host


      Reading the docs, it looks like I can only set one network_mode per service, but I'd like to use something like:



        network_mode: service:elasticsearch
      network_mode: service:mysql


      But this doesn't appear to be possible, unless I'm missing something. Is there a way to handle this? I basically just want localhost:3306 and localhost:9200 to point to each service from within the webapp service.







      docker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 17 at 22:58









      user2856029user2856029

      11




      11






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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%2fsuperuser.com%2fquestions%2f1395566%2fcan-you-use-multiple-network-mode-servicexxx-instances-in-docker-compose%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • 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%2fsuperuser.com%2fquestions%2f1395566%2fcan-you-use-multiple-network-mode-servicexxx-instances-in-docker-compose%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

          How to make a Squid Proxy server?

          Is this a new Fibonacci Identity?

          19世紀