21

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.

5
  • Not a solution but as a work-around, I'm able to run this without the respawn command in the script. Apr 30, 2015 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, 2015 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, 2015 at 22:26
  • Don't you just want to run docker-compose in the background? i.e. docker-compose up -d
    – KCD
    Dec 1, 2016 at 22:49
  • put restart: always in the container spec
    – Lu32
    Mar 13, 2017 at 16:49

3 Answers 3

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.

2
  • Any idea how clean a reboot would be running it this way? Aug 6, 2016 at 19:46
  • 2
    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, 2017 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/

1
  • 2
    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, 2017 at 9:32
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .