How to run Nginx within a Docker container and set it up to reload its configuration every 6h?How to list containers in DockerHow to remove old Docker containersRun a Docker Image as a ContainerHow to enter in a Docker container already running with a new TTYFrom inside of a Docker container, how do I connect to the localhost of the machine?How to keep Docker container running after starting services?How do I run a command on an already existing Docker container?How do I pass environment variables to Docker containers?Nginx & Node inside the same Docker containerTrouble starting docker container with Nginx

Why did Nick Fury not hesitate in blowing up the plane he thought was carrying a nuke?

Why do the i8080 I/O instructions take a byte-sized operand to determine the port?

How do I write real-world stories separate from my country of origin?

What is the required burn to keep a satellite at a Lagrangian point?

Writing "hahaha" versus describing the laugh

Is there an idiom that means that you are in a very strong negotiation position in a negotiation?

What does it mean when みたいな is at the end of a sentence?

Existence of a model of ZFC in which the natural numbers are really the natural numbers

Adobe Illustrator: How can I change the profile of a dashed stroke?

Salesforce bug enabled "Modify All"

Proto-Indo-European (PIE) words with IPA

Download app bundles from App Store to run on iOS Emulator on Mac

Ribbon Cable Cross Talk - Is there a fix after the fact?

What does `LOGFILE=$1:-/var/log/syslog` do?

(For training purposes) Are there any openings with rook pawns that are more effective than others (and if so, what are they)?

If I arrive in the UK, and then head to mainland Europe, does my Schengen visa 90 day limit start when I arrived in the UK, or mainland Europe?

size of pointers and architecture

"Official wife" or "Formal wife"?

Real Analysis: Proof of the equivalent definitions of the derivative.

What defines a person who is circumcised "of the heart"?

Why the work done is positive when bringing 2 opposite charges together?

Ratings matrix plot

What pc resources are used when bruteforcing?

Surface of the 3x3x3 cube as a graph



How to run Nginx within a Docker container and set it up to reload its configuration every 6h?


How to list containers in DockerHow to remove old Docker containersRun a Docker Image as a ContainerHow to enter in a Docker container already running with a new TTYFrom inside of a Docker container, how do I connect to the localhost of the machine?How to keep Docker container running after starting services?How do I run a command on an already existing Docker container?How do I pass environment variables to Docker containers?Nginx & Node inside the same Docker containerTrouble starting docker container with Nginx






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








-1















I'm runnign NGINX in a Docker container, and I'm trying to find a way to start it up using docker run in a way that would order my NGINX to reload its configuration every 6h. I need this to be done, because I also use Certbot in another container, and I'd like the SSL certificate renewal process to be automated and applied, and for that I neen NGINX to reload its configuration on schedule.



At this point I use the folowing docker run sequence (more or less):



docker run --restart=always -d -p 80:80 -p 443:443
--name=nginx_RevPr nginx:latest
/bin/bash -c 'while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g "daemon off;"'



The container created this way is running and working fine. The only problem I have is that I actually don't know if NGINX is really realoading its configuration. docker logs doesn't show anything.



I'd like to approach this problem in a twofold way:



  1. How can I output to terminal / docker logs (echo?) the succcessful nginx -s reload modifying my /bin/bash -c 'while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g "daemon off;"'?

  2. In case I miss something (I'm a beginner for both Docker and NGINX): do you see a way to achieve the results I'd like to get in a more reasonable way?

Please don't suggest Docker Compose.



Thank you for your attention.










share|improve this question
























  • Sorry, but why you want to do this with bash? I think the best solution is to use a time-based job scheduler software like cron or at.

    – Cauê Alves Braz
    Mar 23 at 21:16












  • There are some problems with cron jobs in a dockerized environment. If the cron job runs on the host OS, the system isn't platform agnostic. If the cron runs within the container, it's considered an anti-pattern (containers will be harder to update). But it definitely can be done. I know that some folks run their dockerized NGINX and they pass args for a scheduled reload either in Docker Compose or docker run. I'd like to know how (and a lot of resources over the Internet is misguiding).

    – arek.sobiczewski
    Mar 23 at 21:26

















-1















I'm runnign NGINX in a Docker container, and I'm trying to find a way to start it up using docker run in a way that would order my NGINX to reload its configuration every 6h. I need this to be done, because I also use Certbot in another container, and I'd like the SSL certificate renewal process to be automated and applied, and for that I neen NGINX to reload its configuration on schedule.



At this point I use the folowing docker run sequence (more or less):



docker run --restart=always -d -p 80:80 -p 443:443
--name=nginx_RevPr nginx:latest
/bin/bash -c 'while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g "daemon off;"'



The container created this way is running and working fine. The only problem I have is that I actually don't know if NGINX is really realoading its configuration. docker logs doesn't show anything.



I'd like to approach this problem in a twofold way:



  1. How can I output to terminal / docker logs (echo?) the succcessful nginx -s reload modifying my /bin/bash -c 'while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g "daemon off;"'?

  2. In case I miss something (I'm a beginner for both Docker and NGINX): do you see a way to achieve the results I'd like to get in a more reasonable way?

Please don't suggest Docker Compose.



Thank you for your attention.










share|improve this question
























  • Sorry, but why you want to do this with bash? I think the best solution is to use a time-based job scheduler software like cron or at.

    – Cauê Alves Braz
    Mar 23 at 21:16












  • There are some problems with cron jobs in a dockerized environment. If the cron job runs on the host OS, the system isn't platform agnostic. If the cron runs within the container, it's considered an anti-pattern (containers will be harder to update). But it definitely can be done. I know that some folks run their dockerized NGINX and they pass args for a scheduled reload either in Docker Compose or docker run. I'd like to know how (and a lot of resources over the Internet is misguiding).

    – arek.sobiczewski
    Mar 23 at 21:26













-1












-1








-1








I'm runnign NGINX in a Docker container, and I'm trying to find a way to start it up using docker run in a way that would order my NGINX to reload its configuration every 6h. I need this to be done, because I also use Certbot in another container, and I'd like the SSL certificate renewal process to be automated and applied, and for that I neen NGINX to reload its configuration on schedule.



At this point I use the folowing docker run sequence (more or less):



docker run --restart=always -d -p 80:80 -p 443:443
--name=nginx_RevPr nginx:latest
/bin/bash -c 'while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g "daemon off;"'



The container created this way is running and working fine. The only problem I have is that I actually don't know if NGINX is really realoading its configuration. docker logs doesn't show anything.



I'd like to approach this problem in a twofold way:



  1. How can I output to terminal / docker logs (echo?) the succcessful nginx -s reload modifying my /bin/bash -c 'while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g "daemon off;"'?

  2. In case I miss something (I'm a beginner for both Docker and NGINX): do you see a way to achieve the results I'd like to get in a more reasonable way?

Please don't suggest Docker Compose.



Thank you for your attention.










share|improve this question
















I'm runnign NGINX in a Docker container, and I'm trying to find a way to start it up using docker run in a way that would order my NGINX to reload its configuration every 6h. I need this to be done, because I also use Certbot in another container, and I'd like the SSL certificate renewal process to be automated and applied, and for that I neen NGINX to reload its configuration on schedule.



At this point I use the folowing docker run sequence (more or less):



docker run --restart=always -d -p 80:80 -p 443:443
--name=nginx_RevPr nginx:latest
/bin/bash -c 'while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g "daemon off;"'



The container created this way is running and working fine. The only problem I have is that I actually don't know if NGINX is really realoading its configuration. docker logs doesn't show anything.



I'd like to approach this problem in a twofold way:



  1. How can I output to terminal / docker logs (echo?) the succcessful nginx -s reload modifying my /bin/bash -c 'while :; do sleep 6h & wait $!; nginx -s reload; done & nginx -g "daemon off;"'?

  2. In case I miss something (I'm a beginner for both Docker and NGINX): do you see a way to achieve the results I'd like to get in a more reasonable way?

Please don't suggest Docker Compose.



Thank you for your attention.







linux docker nginx lets-encrypt certbot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 21:29







arek.sobiczewski

















asked Mar 23 at 21:11









arek.sobiczewskiarek.sobiczewski

312




312












  • Sorry, but why you want to do this with bash? I think the best solution is to use a time-based job scheduler software like cron or at.

    – Cauê Alves Braz
    Mar 23 at 21:16












  • There are some problems with cron jobs in a dockerized environment. If the cron job runs on the host OS, the system isn't platform agnostic. If the cron runs within the container, it's considered an anti-pattern (containers will be harder to update). But it definitely can be done. I know that some folks run their dockerized NGINX and they pass args for a scheduled reload either in Docker Compose or docker run. I'd like to know how (and a lot of resources over the Internet is misguiding).

    – arek.sobiczewski
    Mar 23 at 21:26

















  • Sorry, but why you want to do this with bash? I think the best solution is to use a time-based job scheduler software like cron or at.

    – Cauê Alves Braz
    Mar 23 at 21:16












  • There are some problems with cron jobs in a dockerized environment. If the cron job runs on the host OS, the system isn't platform agnostic. If the cron runs within the container, it's considered an anti-pattern (containers will be harder to update). But it definitely can be done. I know that some folks run their dockerized NGINX and they pass args for a scheduled reload either in Docker Compose or docker run. I'd like to know how (and a lot of resources over the Internet is misguiding).

    – arek.sobiczewski
    Mar 23 at 21:26
















Sorry, but why you want to do this with bash? I think the best solution is to use a time-based job scheduler software like cron or at.

– Cauê Alves Braz
Mar 23 at 21:16






Sorry, but why you want to do this with bash? I think the best solution is to use a time-based job scheduler software like cron or at.

– Cauê Alves Braz
Mar 23 at 21:16














There are some problems with cron jobs in a dockerized environment. If the cron job runs on the host OS, the system isn't platform agnostic. If the cron runs within the container, it's considered an anti-pattern (containers will be harder to update). But it definitely can be done. I know that some folks run their dockerized NGINX and they pass args for a scheduled reload either in Docker Compose or docker run. I'd like to know how (and a lot of resources over the Internet is misguiding).

– arek.sobiczewski
Mar 23 at 21:26





There are some problems with cron jobs in a dockerized environment. If the cron job runs on the host OS, the system isn't platform agnostic. If the cron runs within the container, it's considered an anti-pattern (containers will be harder to update). But it definitely can be done. I know that some folks run their dockerized NGINX and they pass args for a scheduled reload either in Docker Compose or docker run. I'd like to know how (and a lot of resources over the Internet is misguiding).

– arek.sobiczewski
Mar 23 at 21:26












1 Answer
1






active

oldest

votes


















0














OK, I got it working.
I changed the CMD args line to:



/bin/sh -c 'while :; do sleep 6h & wait $!; nginx -s reload && echo NGINX config reload for Certbot - OK; done & nginx -g "daemon off;"'



My main mistake was to enter the CMD using /bin/bash, where I should do /bin/sh. And the following nginx -s reload && echo NGINX config reload for Certbot - OK solved the problem with notyfying docker logs about config reload.






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%2f55318428%2fhow-to-run-nginx-within-a-docker-container-and-set-it-up-to-reload-its-configura%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









    0














    OK, I got it working.
    I changed the CMD args line to:



    /bin/sh -c 'while :; do sleep 6h & wait $!; nginx -s reload && echo NGINX config reload for Certbot - OK; done & nginx -g "daemon off;"'



    My main mistake was to enter the CMD using /bin/bash, where I should do /bin/sh. And the following nginx -s reload && echo NGINX config reload for Certbot - OK solved the problem with notyfying docker logs about config reload.






    share|improve this answer



























      0














      OK, I got it working.
      I changed the CMD args line to:



      /bin/sh -c 'while :; do sleep 6h & wait $!; nginx -s reload && echo NGINX config reload for Certbot - OK; done & nginx -g "daemon off;"'



      My main mistake was to enter the CMD using /bin/bash, where I should do /bin/sh. And the following nginx -s reload && echo NGINX config reload for Certbot - OK solved the problem with notyfying docker logs about config reload.






      share|improve this answer

























        0












        0








        0







        OK, I got it working.
        I changed the CMD args line to:



        /bin/sh -c 'while :; do sleep 6h & wait $!; nginx -s reload && echo NGINX config reload for Certbot - OK; done & nginx -g "daemon off;"'



        My main mistake was to enter the CMD using /bin/bash, where I should do /bin/sh. And the following nginx -s reload && echo NGINX config reload for Certbot - OK solved the problem with notyfying docker logs about config reload.






        share|improve this answer













        OK, I got it working.
        I changed the CMD args line to:



        /bin/sh -c 'while :; do sleep 6h & wait $!; nginx -s reload && echo NGINX config reload for Certbot - OK; done & nginx -g "daemon off;"'



        My main mistake was to enter the CMD using /bin/bash, where I should do /bin/sh. And the following nginx -s reload && echo NGINX config reload for Certbot - OK solved the problem with notyfying docker logs about config reload.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 9:05









        arek.sobiczewskiarek.sobiczewski

        312




        312





























            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%2f55318428%2fhow-to-run-nginx-within-a-docker-container-and-set-it-up-to-reload-its-configura%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript