Run DB migration script in docker-compose

Suman Paul
1 min readApr 21, 2018

When running your docker-compose in local, DB migration can be tricky. One possible option is after the stack is running, enter inside the web-server container and run the migration script.

However another option can be running the migration by another container after you MySQL container is up. We can use awesome wait-for-it script for the migration script to wait for the MySQL container to be ready.

Let’s look at a possible node server Dockerfile

Note we are cloning wait-for-it script in the container.

And an accompanying docker-compose.yml

After you run docker-compose up you will notice the migration container will run after MySQL container is ready and run the migration script. Sweet!

If you find this useful, please click the clap 👏 button down below to show your support! ⬇⬇⬇ 🙏🏼

--

--