Skip to content

Run Doctrine migrations automatically on container start #309

Open

Description

@akramer-zibra

Problem / motivation

Currently, after docker pull + restart, migrations must be run manually:

docker exec -it davis sh -c "APP_ENV=prod bin/console doctrine:migrations:migrate --no-interaction"

If this step is forgotten, Davis boots fine but fails in confusing ways (PROPPATCH errors, address books that won't create, etc.) instead of refusing to start. Time spend for upgrading would also decrease with this automation.

Proposed solution

Bake a minimal entrypoint.sh into both docker images that runs migrations before the server starts, then execs the normal process:

#!/bin/sh
set -e

php bin/console doctrine:migrations:migrate --no-interaction

exec "$@"

Wire it up in both Dockerfiles:

COPY ./docker/configurations/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# In Dockerfile
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["php-fpm"]

# In Dockerfile-standalone
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] # Dockerfile-standalone

exec "$@" keeps it transparent to whatever CMD (or a docker run override) supplies.

Known limitations

  • No DB-ready retry: if the database isn't accepting connections yet on first docker-compose up, the migrate step fails fast and the container exits. Compose files don't currently gate depends_on on a healthcheck.
  • No concurrency lock: if the image is ever scaled to multiple replicas, each would race to run migrations on start. Not an issue for the single-instance docker-compose setups in this repo.

Alternatives considered

No response

Area

Docker / deployment

Additional context

No response

Activity

  1. akramer-zibra commented on Oct 15, 2026

    @akramer-zibra
    Author

    PR (#310) also uses healthchecks on both postgres and mysql database containers to address "No DB-ready retry" aspect described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions