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:
$ 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
$ 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
$ 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
$ docker service ps app-migrator
$ docker logs <container id from app-migrator>
$ docker service rm app-migrator
$ docker service update