3 ms·
Does anyone have any advice on using "init" scripts as CMD for the container, vs something like Ansible for post-provisioning? Example: a Django web app... aft
by anentropic 11y ago
Does anyone have any advice on using "init" scripts as CMD for the container, vs something like Ansible for post-provisioning?
Example: a Django web app... after deploying the new version container you need to run migrations etc
Similarly for say RabbitMQ you may need to ensure your vhosts are defined etc... commands that need to be executed against a running server, can't be done in the Dockerfile itself.
So far I've ended up with a bash script in each container that does the necessary init tasks before exec-ing the main process. Or in some cases (Rabbit, Mongo) they first run the server in a limited state, do the init tasks against it, then stop it and exec again as the container process.
Have started to feel it might be cleaner to instead just start the main process and then provision it with Ansible afterwards. But then I lose the ability to have a system up and running just via docker-compose...
- goldbrick 11y agoYou should think of all these operations in terms of the state they persist. For example, a database migration doesn't modify the application at all, but only the data directory wherever your database is running (whether mounted in another container or across a network). Whatever process is orchestrating your containers should take responsibility for running setup chores in a separate, ephemeral container from the eventual application container. docker-compose is often not enough, unfortunately.