Where is ecto.create and ecto.migrate
Closed this issue · 3 comments
I don't see the commands ecto.create and migrate for the phoenix example. When are those done, shouldn't this be done in the Dockerfile?
Hi,
Creating and connecting to databases are typically run time tasks. It wouldn't really belong in a Dockerfile because that happens at build time and your database server likely wouldn't be accessible there.
Personally I run these commands separately (at deploy time). But if you really really wanted them automatically run, you could look into putting them into a Docker entrypoint which would get executed every time the container starts (which is different than on build).
I would think the CMD in Dockerfile is a runtime command and that would be where the ecto.create and migrate commands are run.
If you run these commands separately, when do you specifically run them? Do you run them before docker-compose up?
The CMD
would be reserved for running the server.
If you put them into an entrypoint script they would be run immediately after the container starts.
If you run them manually, it really depends on your use case. I configure my app deployments so I can situationally run database migrations at different points in the life cycle. Sometimes I don't run migrate, other times I migrate after the server comes up (using docker-compose exec
) and other times for longer migrations I'll docker-compose run
the migration while the app is down.