Docker compose auto start on restart

6

I need to launch a docker-compose on an ubuntu-server every time it is restarted.

I tried to create a crontab like this:

@reboot docker-compose -f /home/user/docker-compose/docker-compose.yml up -d

But when I restart it, this has not worked, any ideas?

    
asked by Pablo Cegarra 13.01.2017 в 19:56
source

1 answer

8

The only thing you need to restart itself is restart: always in yml .

So if your docker-compose.yml is this:

version: '2'
services:
  web:
    build: .
    ports:
     - "5000:5000"
    volumes:
     - .:/code
  redis:
    image: "redis:alpine"

Reach with you to put restart: always in the container :

version: '2'
services:
  web:
    restart: always
    build: .
    ports:
     - "5000:5000"
    volumes:
     - .:/code
  redis:
    image: "redis:alpine"

Then, in the folder, you make docker-compose up -d (so that it starts as a separate process) and voila, every time you restart Ubuntu , the container starts.

    
answered by 13.01.2017 / 20:17
source