Best practice to run a bash setup script after creation of container

To answer this question directly, the best way to do that is to write an ENTRYPOINT script in your Dockerfile that does whatever setup is needed, and then ends with exec "$@" to run the normal CMD (or whatever got passed on the command line). The official mysql image entrypoint script is a little bit complex, but it has the right basic pattern.

You might find it easier to use logstash with something like a “gelf” input and an “email” output. (There’s a prebuilt logstash image.) Then you can run your application container with a Docker logging option that points at that container’s published port. Depending on how big your application is, using the combined Elasticsearch/Logstash/Kibana (“ELK”) stack might be overkill, or not.

To a first approximation, no. (And explicitly specifying an SMTP relay host and authentication credentials as configuration is probably less fragile and much less machine-dependent in any case.)

1 Like