Sign inSign up free

845. Run Database Migrations Once, Before the App

medium 20 XP ~10 minHands-on lab

Labs have no container engine, so nothing is started: your files are checked with docker-compose config.

Every replica of scheduler-ui runs npm run migrate && npm start. With three replicas, the migrations run three times at once and fail on locks; sometimes they run before Postgres even accepts connections.

Task

In /home/student/projects/scheduler-ui/compose.yaml:

  • add a service migrate with the same image as app, command ["npm", "run", "migrate"], which isn't restarted after it exits and starts only once db is healthy,
  • app runs just ["npm", "start"], still with 3 replicas, and starts only after db is healthy and migrate has finished successfully.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Part of Docker Fundamentals. Next step: Data Lost on Every Recreate

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.