Database migrations in docker swarm mode Database migrations in docker swarm mode docker docker

Database migrations in docker swarm mode


I believe you can fix this problem by making your overlay network, appnet, attachable. This can be accomplished with the following command:

docker network create --driver overlay --attachable appnet

This should fix the swarm-scoped network error and and allow you to run migrations


This is indeed tricky situation, though I think running the migration during startup might be the the final piece of the puzzle.

The way I do it right now (though not very elegant, it works), is using a message queue (I'm using redis), on app startup, it will send a message to a the queue, informing it that the migration task needs to be run. At the other end of the queue, I have a listener app that will process the queue and run the migration task. The migration task would only run once, since there's only a single instance of the listener running it sequentially. So essentially I'm just using the queue & the listener app to make sure that the migration task runs only once.