Dock roaming database transitions

I have an application consisting of a simple Node application and Mongo db. I wonder how I could start the database migration in docker roaming mode?

Without the swarm mode, I start the migration, first stopping the old version of the application, running the one-time migration command with the new version of the application, and then finally starting the new version of the application:

# Setup is roughly the 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 am testing the setup in docker rock mode so that I can scale easily app. The problem is that in swarm mode you cannot start containers on the swarm network, and therefore I can not get to db to start the migration:

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
6jtmtihmrcjl        appnet              overlay             swarm

# Trying to replicate the manual migration process in swarm mode
$ docker service scale app=0
$ docker run --rm --net appnet app:2 npm run migrate
docker: Error response from daemon: swarm-scoped network (appnet) is not compatible with `docker create` or `docker run`. This network can only be used by a docker service.

app, , . , .

, ?

Edit

, . , , . , !

$ docker service scale app=0
$ docker service create --name app-migrator --network appnet app:2 npm run migrate

# Check when the first app-migrator task is finished and check its output
$ docker service ps app-migrator
$ docker logs <container id from app-migrator>
$ docker service rm app-migrator

# Ready to update the app
$ docker service update --image app:2 --replicas 2 app
+4
2

, , , appnet, . :

docker network create --driver overlay --attachable appnet

+3

, , .

( , ), message queue ( redis), queue, , migration . queue listener app, queue migration. , listener . queue listener app, migration .

0

Source: https://habr.com/ru/post/1654417/


All Articles