How to run commands before the application starts

How to run commands before a Qovery application starts

Running your applications on Qovery is pretty straightforward, but there are many cases where you will need to run some tasks before your application starts, like running database migrations, and it might not be obvious how to do it.


This tutorial will cover how to run tasks when your application is starting. We'll use the case of a database migration with Ruby on Rails, but the same principle can be applied for any framework or command you need to run.

  1. Add an entrypoint script

    The first thing to do is to add an entrypoint script. We'll add it to a docker directory at the project's root, but you can put it anywhere you want.

    Let's create the docker/ with the following content:

    #! /bin/sh
    bundle exec rails db:migrate
    if [[ $? -eq 0 ]] ; then
    echo -e "\n== Failed to migrate. Running setup first. ==\n"
    bundle exec rails db:setup
    # Execute the given or default command:
    exec "$@"

    This script will execute the Rails database migration script. If it fails because the database doesn't exist, it will run the setup command instead.

    The last line is necessary to execute the main command of your Dockerfile.

  2. Give execution permission to the entrypoint script

    You can give execution permission to this file with the following command:

    chmod +x docker/

  3. Add the entrypoint to your Dockerfile

    You will now need to add an ENTRYPOINT instruction to your Dockerfile. (Make sure the file is copied to the image somewhere)

    # ...
    # Dockerfile content omitted for brevity
    # ...
    ENTRYPOINT ["./docker/"]
    EXPOSE 3000
    CMD ["rails", "server", "-p", "3000", "-b", ""]

    You can learn more about Docker entrypoints here:

  4. Deploy your application

    You can now commit and push your changes to your Git repository. The instructions you specified in the file will be executed before the application starts.