Can start Nginx manually inside Docker container, but not automatically via CMD












0















I'm deploying Nginx inside a Docker container (on OpenShift). If I use ENTRYPOINT ["sleep", "infinity"] in my Dockerfile and then issue nginx -g "daemon off;" inside my container, Nginx starts up inside the container as expected. However, if I use ENTRYPOINT ["nginx", "-g", "daemon off;"] in my Dockerfile, the container produces this error message at startup time:




nginx: [emerg] bind() to 0.0.0.0:8000 failed (98: Address already in
use)




What could be the reason for this discrepancy?










share|improve this question

























  • Can you include the entire Dockerfile in your question? Do you have an ENTRYPOINT of any sort?

    – David Maze
    Nov 16 '18 at 15:18
















0















I'm deploying Nginx inside a Docker container (on OpenShift). If I use ENTRYPOINT ["sleep", "infinity"] in my Dockerfile and then issue nginx -g "daemon off;" inside my container, Nginx starts up inside the container as expected. However, if I use ENTRYPOINT ["nginx", "-g", "daemon off;"] in my Dockerfile, the container produces this error message at startup time:




nginx: [emerg] bind() to 0.0.0.0:8000 failed (98: Address already in
use)




What could be the reason for this discrepancy?










share|improve this question

























  • Can you include the entire Dockerfile in your question? Do you have an ENTRYPOINT of any sort?

    – David Maze
    Nov 16 '18 at 15:18














0












0








0


0






I'm deploying Nginx inside a Docker container (on OpenShift). If I use ENTRYPOINT ["sleep", "infinity"] in my Dockerfile and then issue nginx -g "daemon off;" inside my container, Nginx starts up inside the container as expected. However, if I use ENTRYPOINT ["nginx", "-g", "daemon off;"] in my Dockerfile, the container produces this error message at startup time:




nginx: [emerg] bind() to 0.0.0.0:8000 failed (98: Address already in
use)




What could be the reason for this discrepancy?










share|improve this question
















I'm deploying Nginx inside a Docker container (on OpenShift). If I use ENTRYPOINT ["sleep", "infinity"] in my Dockerfile and then issue nginx -g "daemon off;" inside my container, Nginx starts up inside the container as expected. However, if I use ENTRYPOINT ["nginx", "-g", "daemon off;"] in my Dockerfile, the container produces this error message at startup time:




nginx: [emerg] bind() to 0.0.0.0:8000 failed (98: Address already in
use)




What could be the reason for this discrepancy?







docker nginx openshift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 23:28







rookie099

















asked Nov 16 '18 at 14:50









rookie099rookie099

400110




400110













  • Can you include the entire Dockerfile in your question? Do you have an ENTRYPOINT of any sort?

    – David Maze
    Nov 16 '18 at 15:18



















  • Can you include the entire Dockerfile in your question? Do you have an ENTRYPOINT of any sort?

    – David Maze
    Nov 16 '18 at 15:18

















Can you include the entire Dockerfile in your question? Do you have an ENTRYPOINT of any sort?

– David Maze
Nov 16 '18 at 15:18





Can you include the entire Dockerfile in your question? Do you have an ENTRYPOINT of any sort?

– David Maze
Nov 16 '18 at 15:18












2 Answers
2






active

oldest

votes


















0














You should use CMD ["nginx", "-g", "daemon off;"] and leave ENTRYPOINT as default.






share|improve this answer































    -1














    I've now found a workaround. Starting nginx indirectly from ENTRYPOINT ["/usr/local/bin/start.sh"] works when start.sh is as follows:



    #!/bin/bash
    nginx
    sleep infinity


    Strangely this invocation of nginx inside start.sh still produces the same error messages, but since it is followed by sleep infinity the ENTRYPOINT script now can succeed. Only if I do not invoke nginx at all, the error messages disappears but then Nginx does not run either. Strange indeed.



    BTW, I'm using the Debian version of nginx and adjust the user directive in /etc/nginx/nginx.conf in Dockerfile as well as several directory permissions for meeting OpenShift's requirements (where container images do not run as root but as random uids).



    UPDATE The root cause turned out to be an error whereby the same container instance ran twice inside a pod. This (of course, in hindsight) led to the same server being started twice on the same node and hence to the error message about binding in the "second" container. I had always observed only the "second" container so far and therefore encountered the error. After resolving this, ENTRYPOINT ["nginx", "-g", "daemon off;"] now works as well.






    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%2f53340155%2fcan-start-nginx-manually-inside-docker-container-but-not-automatically-via-cmd%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You should use CMD ["nginx", "-g", "daemon off;"] and leave ENTRYPOINT as default.






      share|improve this answer




























        0














        You should use CMD ["nginx", "-g", "daemon off;"] and leave ENTRYPOINT as default.






        share|improve this answer


























          0












          0








          0







          You should use CMD ["nginx", "-g", "daemon off;"] and leave ENTRYPOINT as default.






          share|improve this answer













          You should use CMD ["nginx", "-g", "daemon off;"] and leave ENTRYPOINT as default.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 8:57









          SiyuSiyu

          2,8081927




          2,8081927

























              -1














              I've now found a workaround. Starting nginx indirectly from ENTRYPOINT ["/usr/local/bin/start.sh"] works when start.sh is as follows:



              #!/bin/bash
              nginx
              sleep infinity


              Strangely this invocation of nginx inside start.sh still produces the same error messages, but since it is followed by sleep infinity the ENTRYPOINT script now can succeed. Only if I do not invoke nginx at all, the error messages disappears but then Nginx does not run either. Strange indeed.



              BTW, I'm using the Debian version of nginx and adjust the user directive in /etc/nginx/nginx.conf in Dockerfile as well as several directory permissions for meeting OpenShift's requirements (where container images do not run as root but as random uids).



              UPDATE The root cause turned out to be an error whereby the same container instance ran twice inside a pod. This (of course, in hindsight) led to the same server being started twice on the same node and hence to the error message about binding in the "second" container. I had always observed only the "second" container so far and therefore encountered the error. After resolving this, ENTRYPOINT ["nginx", "-g", "daemon off;"] now works as well.






              share|improve this answer






























                -1














                I've now found a workaround. Starting nginx indirectly from ENTRYPOINT ["/usr/local/bin/start.sh"] works when start.sh is as follows:



                #!/bin/bash
                nginx
                sleep infinity


                Strangely this invocation of nginx inside start.sh still produces the same error messages, but since it is followed by sleep infinity the ENTRYPOINT script now can succeed. Only if I do not invoke nginx at all, the error messages disappears but then Nginx does not run either. Strange indeed.



                BTW, I'm using the Debian version of nginx and adjust the user directive in /etc/nginx/nginx.conf in Dockerfile as well as several directory permissions for meeting OpenShift's requirements (where container images do not run as root but as random uids).



                UPDATE The root cause turned out to be an error whereby the same container instance ran twice inside a pod. This (of course, in hindsight) led to the same server being started twice on the same node and hence to the error message about binding in the "second" container. I had always observed only the "second" container so far and therefore encountered the error. After resolving this, ENTRYPOINT ["nginx", "-g", "daemon off;"] now works as well.






                share|improve this answer




























                  -1












                  -1








                  -1







                  I've now found a workaround. Starting nginx indirectly from ENTRYPOINT ["/usr/local/bin/start.sh"] works when start.sh is as follows:



                  #!/bin/bash
                  nginx
                  sleep infinity


                  Strangely this invocation of nginx inside start.sh still produces the same error messages, but since it is followed by sleep infinity the ENTRYPOINT script now can succeed. Only if I do not invoke nginx at all, the error messages disappears but then Nginx does not run either. Strange indeed.



                  BTW, I'm using the Debian version of nginx and adjust the user directive in /etc/nginx/nginx.conf in Dockerfile as well as several directory permissions for meeting OpenShift's requirements (where container images do not run as root but as random uids).



                  UPDATE The root cause turned out to be an error whereby the same container instance ran twice inside a pod. This (of course, in hindsight) led to the same server being started twice on the same node and hence to the error message about binding in the "second" container. I had always observed only the "second" container so far and therefore encountered the error. After resolving this, ENTRYPOINT ["nginx", "-g", "daemon off;"] now works as well.






                  share|improve this answer















                  I've now found a workaround. Starting nginx indirectly from ENTRYPOINT ["/usr/local/bin/start.sh"] works when start.sh is as follows:



                  #!/bin/bash
                  nginx
                  sleep infinity


                  Strangely this invocation of nginx inside start.sh still produces the same error messages, but since it is followed by sleep infinity the ENTRYPOINT script now can succeed. Only if I do not invoke nginx at all, the error messages disappears but then Nginx does not run either. Strange indeed.



                  BTW, I'm using the Debian version of nginx and adjust the user directive in /etc/nginx/nginx.conf in Dockerfile as well as several directory permissions for meeting OpenShift's requirements (where container images do not run as root but as random uids).



                  UPDATE The root cause turned out to be an error whereby the same container instance ran twice inside a pod. This (of course, in hindsight) led to the same server being started twice on the same node and hence to the error message about binding in the "second" container. I had always observed only the "second" container so far and therefore encountered the error. After resolving this, ENTRYPOINT ["nginx", "-g", "daemon off;"] now works as well.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 23 '18 at 5:31

























                  answered Nov 20 '18 at 13:42









                  rookie099rookie099

                  400110




                  400110






























                      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%2f53340155%2fcan-start-nginx-manually-inside-docker-container-but-not-automatically-via-cmd%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

                      Wiesbaden

                      Marschland

                      Dieringhausen