How to expose a port from a Docker Swarm without breaking DNS lookups?












0















I have a web service running as a Spring Boot application inside a Docker container. The web service accesses an external Cassandra database. The web service is exposed from the Docker container by publishing it's HTTP port (8081). The container images are built with 'openjdk:8-jre-alpine' as the base and the only additional changes are the application JAR and a mount for the configuration file. Docker is installed on an Ubuntu VM running in Azure.



This works great as a plain old container but when I run it as part of a Docker swarm the DNS lookups to find the Cassandra database fail.



I don't have an ops background, and networking has never been my strong point, but I've worked out that Docker changes the '/etc/resolv.conf' file when I expose a port from a container running in a swarm and this breaks DNS lookups.



Here's some code to explain a bit more about my setup.



Dockerfile (simplified for security):



FROM openjdk:8-jre-alpine
WORKDIR /service
COPY ./target/application.jar /service
VOLUME /service/config
CMD java -jar application.jar --spring.config.name=message-processor


Starting a simple container:



docker container run -d --restart=unless-stopped --name message-processor --publish 8081:8081 -v /config/jenkins:/service/config -e SPRING_PROFILES_ACTIVE=jenkins -e SPRING_CONFIG_NAME=message-processor message-processor:jenkins


Starting a Swarm service:



docker service create --replicas 2 --name message-processor --publish 8081:8081 --mount type=bind,source=/config/jenkins,target=/service/config -e SPRING_PROFILES_ACTIVE=jenkins -e SPRING_CONFIG_NAME=message-processor message-processor:jenkins


I won't post the contents of the respoective '/etc/resolve.conf' becuase they contain various IP addresses and domain names. In the working container the 'nameserver' value is the same as the host. In the Swam containers where DNS isn't working the 'nameserver' is set to 127.0.0.11.



I can get DNS to work in the Swarm containers if I manually change '/etc/resolve.conf' but this doesn't seem like the right thing to do.



I've started researching and experimenting with Docker networks but it's slow going and I don't feel I'm making much progress.










share|improve this question



























    0















    I have a web service running as a Spring Boot application inside a Docker container. The web service accesses an external Cassandra database. The web service is exposed from the Docker container by publishing it's HTTP port (8081). The container images are built with 'openjdk:8-jre-alpine' as the base and the only additional changes are the application JAR and a mount for the configuration file. Docker is installed on an Ubuntu VM running in Azure.



    This works great as a plain old container but when I run it as part of a Docker swarm the DNS lookups to find the Cassandra database fail.



    I don't have an ops background, and networking has never been my strong point, but I've worked out that Docker changes the '/etc/resolv.conf' file when I expose a port from a container running in a swarm and this breaks DNS lookups.



    Here's some code to explain a bit more about my setup.



    Dockerfile (simplified for security):



    FROM openjdk:8-jre-alpine
    WORKDIR /service
    COPY ./target/application.jar /service
    VOLUME /service/config
    CMD java -jar application.jar --spring.config.name=message-processor


    Starting a simple container:



    docker container run -d --restart=unless-stopped --name message-processor --publish 8081:8081 -v /config/jenkins:/service/config -e SPRING_PROFILES_ACTIVE=jenkins -e SPRING_CONFIG_NAME=message-processor message-processor:jenkins


    Starting a Swarm service:



    docker service create --replicas 2 --name message-processor --publish 8081:8081 --mount type=bind,source=/config/jenkins,target=/service/config -e SPRING_PROFILES_ACTIVE=jenkins -e SPRING_CONFIG_NAME=message-processor message-processor:jenkins


    I won't post the contents of the respoective '/etc/resolve.conf' becuase they contain various IP addresses and domain names. In the working container the 'nameserver' value is the same as the host. In the Swam containers where DNS isn't working the 'nameserver' is set to 127.0.0.11.



    I can get DNS to work in the Swarm containers if I manually change '/etc/resolve.conf' but this doesn't seem like the right thing to do.



    I've started researching and experimenting with Docker networks but it's slow going and I don't feel I'm making much progress.










    share|improve this question

























      0












      0








      0








      I have a web service running as a Spring Boot application inside a Docker container. The web service accesses an external Cassandra database. The web service is exposed from the Docker container by publishing it's HTTP port (8081). The container images are built with 'openjdk:8-jre-alpine' as the base and the only additional changes are the application JAR and a mount for the configuration file. Docker is installed on an Ubuntu VM running in Azure.



      This works great as a plain old container but when I run it as part of a Docker swarm the DNS lookups to find the Cassandra database fail.



      I don't have an ops background, and networking has never been my strong point, but I've worked out that Docker changes the '/etc/resolv.conf' file when I expose a port from a container running in a swarm and this breaks DNS lookups.



      Here's some code to explain a bit more about my setup.



      Dockerfile (simplified for security):



      FROM openjdk:8-jre-alpine
      WORKDIR /service
      COPY ./target/application.jar /service
      VOLUME /service/config
      CMD java -jar application.jar --spring.config.name=message-processor


      Starting a simple container:



      docker container run -d --restart=unless-stopped --name message-processor --publish 8081:8081 -v /config/jenkins:/service/config -e SPRING_PROFILES_ACTIVE=jenkins -e SPRING_CONFIG_NAME=message-processor message-processor:jenkins


      Starting a Swarm service:



      docker service create --replicas 2 --name message-processor --publish 8081:8081 --mount type=bind,source=/config/jenkins,target=/service/config -e SPRING_PROFILES_ACTIVE=jenkins -e SPRING_CONFIG_NAME=message-processor message-processor:jenkins


      I won't post the contents of the respoective '/etc/resolve.conf' becuase they contain various IP addresses and domain names. In the working container the 'nameserver' value is the same as the host. In the Swam containers where DNS isn't working the 'nameserver' is set to 127.0.0.11.



      I can get DNS to work in the Swarm containers if I manually change '/etc/resolve.conf' but this doesn't seem like the right thing to do.



      I've started researching and experimenting with Docker networks but it's slow going and I don't feel I'm making much progress.










      share|improve this question














      I have a web service running as a Spring Boot application inside a Docker container. The web service accesses an external Cassandra database. The web service is exposed from the Docker container by publishing it's HTTP port (8081). The container images are built with 'openjdk:8-jre-alpine' as the base and the only additional changes are the application JAR and a mount for the configuration file. Docker is installed on an Ubuntu VM running in Azure.



      This works great as a plain old container but when I run it as part of a Docker swarm the DNS lookups to find the Cassandra database fail.



      I don't have an ops background, and networking has never been my strong point, but I've worked out that Docker changes the '/etc/resolv.conf' file when I expose a port from a container running in a swarm and this breaks DNS lookups.



      Here's some code to explain a bit more about my setup.



      Dockerfile (simplified for security):



      FROM openjdk:8-jre-alpine
      WORKDIR /service
      COPY ./target/application.jar /service
      VOLUME /service/config
      CMD java -jar application.jar --spring.config.name=message-processor


      Starting a simple container:



      docker container run -d --restart=unless-stopped --name message-processor --publish 8081:8081 -v /config/jenkins:/service/config -e SPRING_PROFILES_ACTIVE=jenkins -e SPRING_CONFIG_NAME=message-processor message-processor:jenkins


      Starting a Swarm service:



      docker service create --replicas 2 --name message-processor --publish 8081:8081 --mount type=bind,source=/config/jenkins,target=/service/config -e SPRING_PROFILES_ACTIVE=jenkins -e SPRING_CONFIG_NAME=message-processor message-processor:jenkins


      I won't post the contents of the respoective '/etc/resolve.conf' becuase they contain various IP addresses and domain names. In the working container the 'nameserver' value is the same as the host. In the Swam containers where DNS isn't working the 'nameserver' is set to 127.0.0.11.



      I can get DNS to work in the Swarm containers if I manually change '/etc/resolve.conf' but this doesn't seem like the right thing to do.



      I've started researching and experimenting with Docker networks but it's slow going and I don't feel I'm making much progress.







      networking docker-swarm






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 12:03









      jafwattjafwatt

      9613




      9613
























          0






          active

          oldest

          votes











          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%2f53280652%2fhow-to-expose-a-port-from-a-docker-swarm-without-breaking-dns-lookups%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 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%2f53280652%2fhow-to-expose-a-port-from-a-docker-swarm-without-breaking-dns-lookups%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

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma