faradayio / cage

Develop and deploy complex Docker applications
http://cage.faraday.io
Apache License 2.0
307 stars 26 forks source link

`up --init`: Initialize containers at startup #48

Closed emk closed 7 years ago

emk commented 7 years ago

In order to support initializating containers easily, we add an up --init command, which can invoke one or more cage run tasks to create database, apply migrations, etc. In order to make this reliable, we have a little magic:

  1. We query the Docker daemon at runtime to get a list of exported ports for a container and its IP address.
  2. We "port scan" the container to repeatedly until all the ports open up.

We also use this new Docker support to enhance cage status a bit.

emk commented 7 years ago

I'm going to go ahead and merge this now so that I can work on another bug that will share the same test script. But please feel free to review it anyway!

erithmetic commented 7 years ago

@emk my one concern is that if you have a service with restart: always, running these scripts via docker run is going to leave containers continually running/restarting.

emk commented 7 years ago

@dkastner Honestly, I really feel like cage containers shouldn't be declaring restart: "always" everywhere. If something falls over in development mode, then we shouldn't just keep endlessly restarting it. Instead, we should perhaps consider having some kind of cage watch mode that notifies the user of things like this.

And we could always have a plugin which strips restart: completely in development or test mode, or one which adds it in for release mode.