How to run docker-compose at bootup?












20














This is on an Ubuntu 14.04 LTS VM running Docker and I suspect respawn is the cause of my problem but not sure of the ideal solution.



Current upstart script (cat /etc/init/dockersuitecrm.conf)



description "Start docker containers"
author "Batman"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start
end script


This 'works' in that myapp is alive and responsive but /sbin/init takes up all the CPU when I monitor with htop. If I remove the entry from upstart (sudo rm /etc/init/dockersuitecrm.conf) and manually SSH in and run docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start I don't see the cpu at 100% issue and as before myapp is again alive and responsive.



So I suspect the way I'm starting docker-compose above is incorrect. What's the right way to start docker-compose is always running without manual intervention?



EDIT: Shouldn't matter but /usr/bin/myapp -> /home/batman/dockerapps/myapp as a symbolic link.










share|improve this question
























  • Not a solution but as a work-around, I'm able to run this without the respawn command in the script.
    – DeepSpace101
    Apr 30 '15 at 18:50










  • Same question, but I saw this: serverfault.com/questions/615820/…. The magic is with using docker-compose start.
    – Mark Lopez
    Jun 19 '15 at 17:53










  • I have a similar config but don't use a script block. Maybe that is part of the problem? I have chdir /usr/bin/myapp/ and on the next line exec docker-compose up instead.
    – jmreicha
    Jul 9 '15 at 22:26










  • Don't you just want to run docker-compose in the background? i.e. docker-compose up -d
    – KCD
    Dec 1 '16 at 22:49










  • put restart: always in the container spec
    – Lu32
    Mar 13 '17 at 16:49
















20














This is on an Ubuntu 14.04 LTS VM running Docker and I suspect respawn is the cause of my problem but not sure of the ideal solution.



Current upstart script (cat /etc/init/dockersuitecrm.conf)



description "Start docker containers"
author "Batman"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start
end script


This 'works' in that myapp is alive and responsive but /sbin/init takes up all the CPU when I monitor with htop. If I remove the entry from upstart (sudo rm /etc/init/dockersuitecrm.conf) and manually SSH in and run docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start I don't see the cpu at 100% issue and as before myapp is again alive and responsive.



So I suspect the way I'm starting docker-compose above is incorrect. What's the right way to start docker-compose is always running without manual intervention?



EDIT: Shouldn't matter but /usr/bin/myapp -> /home/batman/dockerapps/myapp as a symbolic link.










share|improve this question
























  • Not a solution but as a work-around, I'm able to run this without the respawn command in the script.
    – DeepSpace101
    Apr 30 '15 at 18:50










  • Same question, but I saw this: serverfault.com/questions/615820/…. The magic is with using docker-compose start.
    – Mark Lopez
    Jun 19 '15 at 17:53










  • I have a similar config but don't use a script block. Maybe that is part of the problem? I have chdir /usr/bin/myapp/ and on the next line exec docker-compose up instead.
    – jmreicha
    Jul 9 '15 at 22:26










  • Don't you just want to run docker-compose in the background? i.e. docker-compose up -d
    – KCD
    Dec 1 '16 at 22:49










  • put restart: always in the container spec
    – Lu32
    Mar 13 '17 at 16:49














20












20








20


1





This is on an Ubuntu 14.04 LTS VM running Docker and I suspect respawn is the cause of my problem but not sure of the ideal solution.



Current upstart script (cat /etc/init/dockersuitecrm.conf)



description "Start docker containers"
author "Batman"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start
end script


This 'works' in that myapp is alive and responsive but /sbin/init takes up all the CPU when I monitor with htop. If I remove the entry from upstart (sudo rm /etc/init/dockersuitecrm.conf) and manually SSH in and run docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start I don't see the cpu at 100% issue and as before myapp is again alive and responsive.



So I suspect the way I'm starting docker-compose above is incorrect. What's the right way to start docker-compose is always running without manual intervention?



EDIT: Shouldn't matter but /usr/bin/myapp -> /home/batman/dockerapps/myapp as a symbolic link.










share|improve this question















This is on an Ubuntu 14.04 LTS VM running Docker and I suspect respawn is the cause of my problem but not sure of the ideal solution.



Current upstart script (cat /etc/init/dockersuitecrm.conf)



description "Start docker containers"
author "Batman"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start
end script


This 'works' in that myapp is alive and responsive but /sbin/init takes up all the CPU when I monitor with htop. If I remove the entry from upstart (sudo rm /etc/init/dockersuitecrm.conf) and manually SSH in and run docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start I don't see the cpu at 100% issue and as before myapp is again alive and responsive.



So I suspect the way I'm starting docker-compose above is incorrect. What's the right way to start docker-compose is always running without manual intervention?



EDIT: Shouldn't matter but /usr/bin/myapp -> /home/batman/dockerapps/myapp as a symbolic link.







14.04 server upstart docker






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 23 '15 at 17:03







DeepSpace101

















asked Apr 23 '15 at 16:54









DeepSpace101DeepSpace101

2381210




2381210












  • Not a solution but as a work-around, I'm able to run this without the respawn command in the script.
    – DeepSpace101
    Apr 30 '15 at 18:50










  • Same question, but I saw this: serverfault.com/questions/615820/…. The magic is with using docker-compose start.
    – Mark Lopez
    Jun 19 '15 at 17:53










  • I have a similar config but don't use a script block. Maybe that is part of the problem? I have chdir /usr/bin/myapp/ and on the next line exec docker-compose up instead.
    – jmreicha
    Jul 9 '15 at 22:26










  • Don't you just want to run docker-compose in the background? i.e. docker-compose up -d
    – KCD
    Dec 1 '16 at 22:49










  • put restart: always in the container spec
    – Lu32
    Mar 13 '17 at 16:49


















  • Not a solution but as a work-around, I'm able to run this without the respawn command in the script.
    – DeepSpace101
    Apr 30 '15 at 18:50










  • Same question, but I saw this: serverfault.com/questions/615820/…. The magic is with using docker-compose start.
    – Mark Lopez
    Jun 19 '15 at 17:53










  • I have a similar config but don't use a script block. Maybe that is part of the problem? I have chdir /usr/bin/myapp/ and on the next line exec docker-compose up instead.
    – jmreicha
    Jul 9 '15 at 22:26










  • Don't you just want to run docker-compose in the background? i.e. docker-compose up -d
    – KCD
    Dec 1 '16 at 22:49










  • put restart: always in the container spec
    – Lu32
    Mar 13 '17 at 16:49
















Not a solution but as a work-around, I'm able to run this without the respawn command in the script.
– DeepSpace101
Apr 30 '15 at 18:50




Not a solution but as a work-around, I'm able to run this without the respawn command in the script.
– DeepSpace101
Apr 30 '15 at 18:50












Same question, but I saw this: serverfault.com/questions/615820/…. The magic is with using docker-compose start.
– Mark Lopez
Jun 19 '15 at 17:53




Same question, but I saw this: serverfault.com/questions/615820/…. The magic is with using docker-compose start.
– Mark Lopez
Jun 19 '15 at 17:53












I have a similar config but don't use a script block. Maybe that is part of the problem? I have chdir /usr/bin/myapp/ and on the next line exec docker-compose up instead.
– jmreicha
Jul 9 '15 at 22:26




I have a similar config but don't use a script block. Maybe that is part of the problem? I have chdir /usr/bin/myapp/ and on the next line exec docker-compose up instead.
– jmreicha
Jul 9 '15 at 22:26












Don't you just want to run docker-compose in the background? i.e. docker-compose up -d
– KCD
Dec 1 '16 at 22:49




Don't you just want to run docker-compose in the background? i.e. docker-compose up -d
– KCD
Dec 1 '16 at 22:49












put restart: always in the container spec
– Lu32
Mar 13 '17 at 16:49




put restart: always in the container spec
– Lu32
Mar 13 '17 at 16:49










3 Answers
3






active

oldest

votes


















9














Simply use crontab, instead of using a time intervall simply say @reboot



So login as the user who should start this script and type the command



crontab -e


and then enter



@reboot /better/enter/fullpath/here/docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start


Reboot the system and see if it works. There's one advantage over upstart, even it it is started a little bit later, you don't have to worry much about dependcies like networking, etc. to be up already.






share|improve this answer





















  • Any idea how clean a reboot would be running it this way?
    – Justin Smith
    Aug 6 '16 at 19:46






  • 1




    Sorry, but this is not a very good answer. It might work from time to time, but as cron might be loaded before other docker requirements, you run into a race condition.
    – Otheus
    Aug 7 '17 at 9:31



















2














Assuming you're using version 2 of Docker Compose definitions in you docker-compose.yml, you can do the following:



Defining restart: always like so:



version: '2'
services:
web:
image: nginx
restart: always


Reference: https://docs.docker.com/compose/compose-file/compose-file-v2/






share|improve this answer

















  • 1




    The question is, which docker's site doesn't answer, was: "What's the right way to start docker-compose is always running without manual intervention?"
    – Otheus
    Aug 7 '17 at 9:32



















0














Docker is not ready immediately
If you run the script too early, nothing will happen.
The docker will start responding to the docker ps command as soon as it is ready so you can use this trick in crontab:



nano /etc/crontabs/root



@reboot /usr/bin/docker ps && /usr/bin/docker-compose -f /prod.yml start






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    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%2faskubuntu.com%2fquestions%2f612928%2fhow-to-run-docker-compose-at-bootup%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9














    Simply use crontab, instead of using a time intervall simply say @reboot



    So login as the user who should start this script and type the command



    crontab -e


    and then enter



    @reboot /better/enter/fullpath/here/docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start


    Reboot the system and see if it works. There's one advantage over upstart, even it it is started a little bit later, you don't have to worry much about dependcies like networking, etc. to be up already.






    share|improve this answer





















    • Any idea how clean a reboot would be running it this way?
      – Justin Smith
      Aug 6 '16 at 19:46






    • 1




      Sorry, but this is not a very good answer. It might work from time to time, but as cron might be loaded before other docker requirements, you run into a race condition.
      – Otheus
      Aug 7 '17 at 9:31
















    9














    Simply use crontab, instead of using a time intervall simply say @reboot



    So login as the user who should start this script and type the command



    crontab -e


    and then enter



    @reboot /better/enter/fullpath/here/docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start


    Reboot the system and see if it works. There's one advantage over upstart, even it it is started a little bit later, you don't have to worry much about dependcies like networking, etc. to be up already.






    share|improve this answer





















    • Any idea how clean a reboot would be running it this way?
      – Justin Smith
      Aug 6 '16 at 19:46






    • 1




      Sorry, but this is not a very good answer. It might work from time to time, but as cron might be loaded before other docker requirements, you run into a race condition.
      – Otheus
      Aug 7 '17 at 9:31














    9












    9








    9






    Simply use crontab, instead of using a time intervall simply say @reboot



    So login as the user who should start this script and type the command



    crontab -e


    and then enter



    @reboot /better/enter/fullpath/here/docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start


    Reboot the system and see if it works. There's one advantage over upstart, even it it is started a little bit later, you don't have to worry much about dependcies like networking, etc. to be up already.






    share|improve this answer












    Simply use crontab, instead of using a time intervall simply say @reboot



    So login as the user who should start this script and type the command



    crontab -e


    and then enter



    @reboot /better/enter/fullpath/here/docker-compose -f /usr/bin/myapp/docker-compose.yml -p myapp start


    Reboot the system and see if it works. There's one advantage over upstart, even it it is started a little bit later, you don't have to worry much about dependcies like networking, etc. to be up already.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 30 '16 at 6:03









    s1mmels1mmel

    1,165516




    1,165516












    • Any idea how clean a reboot would be running it this way?
      – Justin Smith
      Aug 6 '16 at 19:46






    • 1




      Sorry, but this is not a very good answer. It might work from time to time, but as cron might be loaded before other docker requirements, you run into a race condition.
      – Otheus
      Aug 7 '17 at 9:31


















    • Any idea how clean a reboot would be running it this way?
      – Justin Smith
      Aug 6 '16 at 19:46






    • 1




      Sorry, but this is not a very good answer. It might work from time to time, but as cron might be loaded before other docker requirements, you run into a race condition.
      – Otheus
      Aug 7 '17 at 9:31
















    Any idea how clean a reboot would be running it this way?
    – Justin Smith
    Aug 6 '16 at 19:46




    Any idea how clean a reboot would be running it this way?
    – Justin Smith
    Aug 6 '16 at 19:46




    1




    1




    Sorry, but this is not a very good answer. It might work from time to time, but as cron might be loaded before other docker requirements, you run into a race condition.
    – Otheus
    Aug 7 '17 at 9:31




    Sorry, but this is not a very good answer. It might work from time to time, but as cron might be loaded before other docker requirements, you run into a race condition.
    – Otheus
    Aug 7 '17 at 9:31













    2














    Assuming you're using version 2 of Docker Compose definitions in you docker-compose.yml, you can do the following:



    Defining restart: always like so:



    version: '2'
    services:
    web:
    image: nginx
    restart: always


    Reference: https://docs.docker.com/compose/compose-file/compose-file-v2/






    share|improve this answer

















    • 1




      The question is, which docker's site doesn't answer, was: "What's the right way to start docker-compose is always running without manual intervention?"
      – Otheus
      Aug 7 '17 at 9:32
















    2














    Assuming you're using version 2 of Docker Compose definitions in you docker-compose.yml, you can do the following:



    Defining restart: always like so:



    version: '2'
    services:
    web:
    image: nginx
    restart: always


    Reference: https://docs.docker.com/compose/compose-file/compose-file-v2/






    share|improve this answer

















    • 1




      The question is, which docker's site doesn't answer, was: "What's the right way to start docker-compose is always running without manual intervention?"
      – Otheus
      Aug 7 '17 at 9:32














    2












    2








    2






    Assuming you're using version 2 of Docker Compose definitions in you docker-compose.yml, you can do the following:



    Defining restart: always like so:



    version: '2'
    services:
    web:
    image: nginx
    restart: always


    Reference: https://docs.docker.com/compose/compose-file/compose-file-v2/






    share|improve this answer












    Assuming you're using version 2 of Docker Compose definitions in you docker-compose.yml, you can do the following:



    Defining restart: always like so:



    version: '2'
    services:
    web:
    image: nginx
    restart: always


    Reference: https://docs.docker.com/compose/compose-file/compose-file-v2/







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 7 '17 at 10:57









    Sergei FilippovSergei Filippov

    813




    813








    • 1




      The question is, which docker's site doesn't answer, was: "What's the right way to start docker-compose is always running without manual intervention?"
      – Otheus
      Aug 7 '17 at 9:32














    • 1




      The question is, which docker's site doesn't answer, was: "What's the right way to start docker-compose is always running without manual intervention?"
      – Otheus
      Aug 7 '17 at 9:32








    1




    1




    The question is, which docker's site doesn't answer, was: "What's the right way to start docker-compose is always running without manual intervention?"
    – Otheus
    Aug 7 '17 at 9:32




    The question is, which docker's site doesn't answer, was: "What's the right way to start docker-compose is always running without manual intervention?"
    – Otheus
    Aug 7 '17 at 9:32











    0














    Docker is not ready immediately
    If you run the script too early, nothing will happen.
    The docker will start responding to the docker ps command as soon as it is ready so you can use this trick in crontab:



    nano /etc/crontabs/root



    @reboot /usr/bin/docker ps && /usr/bin/docker-compose -f /prod.yml start






    share|improve this answer


























      0














      Docker is not ready immediately
      If you run the script too early, nothing will happen.
      The docker will start responding to the docker ps command as soon as it is ready so you can use this trick in crontab:



      nano /etc/crontabs/root



      @reboot /usr/bin/docker ps && /usr/bin/docker-compose -f /prod.yml start






      share|improve this answer
























        0












        0








        0






        Docker is not ready immediately
        If you run the script too early, nothing will happen.
        The docker will start responding to the docker ps command as soon as it is ready so you can use this trick in crontab:



        nano /etc/crontabs/root



        @reboot /usr/bin/docker ps && /usr/bin/docker-compose -f /prod.yml start






        share|improve this answer












        Docker is not ready immediately
        If you run the script too early, nothing will happen.
        The docker will start responding to the docker ps command as soon as it is ready so you can use this trick in crontab:



        nano /etc/crontabs/root



        @reboot /usr/bin/docker ps && /usr/bin/docker-compose -f /prod.yml start







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 17 '18 at 18:54









        Evgeny SavelovEvgeny Savelov

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2faskubuntu.com%2fquestions%2f612928%2fhow-to-run-docker-compose-at-bootup%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

            Ellipse (mathématiques)

            Quarter-circle Tiles

            Mont Emei