How to run docker-compose at bootup?

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.


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/