Database migrations in docker swarm mode -


i have application consists of simple node app , mongo db. wonder, how run database migrations in docker swarm mode?

without swarm mode run migrations stopping first old version of application, running one-off migration command new version of application , starting new version of app:

# setup following $ docker network create appnet $ docker run -d --name db --net appnet db:1 $ docker run -d --name app --net appnet -p 80:80 app:1  # update process $ docker stop app && docker rm app $ docker run --rm --net appnet app:2 npm run migrate $ docker run -d --name app --net appnet -p 80:80 app:2 

now i'm testing setup in docker swarm mode scale app. problem in swarm mode 1 can't start containers in swarm network , can't reach db run migrations:

$ docker network ls network id          name                driver              scope 6jtmtihmrcjl        appnet              overlay             swarm  # trying replicate manual migration process in swarm mode $ docker service scale app=0 $ docker run --rm --net appnet app:2 npm run migrate docker: error response daemon: swarm-scoped network (appnet) not compatible `docker create` or `docker run`. network can used docker service. 

i don't want run migration command during app startup either, there might several instances launching , potentially screw database. automatic migrations scary, want avoid them @ costs.

do have idea how implement manual migration step in docker swarm mode?

edit

i found out dirty hack allows replicate original workflow. idea create new service custom command , remove when 1 of tasks finished. far pleasant usage, better alternatives more welcome!

$ docker service scale app=0 $ docker service create --name app-migrator --network appnet app:2 npm run migrate  # check when first app-migrator task finished , check output $ docker service ps app-migrator $ docker logs <container id app-migrator> $ docker service rm app-migrator  # ready update app $ docker service update --image app:2 --replicas 2 app 

i believe can fix problem making overlay network, appnet, attachable. can accomplished following command:

docker network create --driver overlay --attachable appnet 

this should fix swarm-scoped network error , and allow run migrations


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -