In order for servers to communicate I guess you
would need to configure port forwarding properly,
so that routing server would be able to access
shards, and vice versa.
With Vagrant one can configure port forwarding,
and in this case, I suppose also needs to be
ports being properly
configured for Docker containers. Refer to Vagrant Networking
Configuration page and Vagrant's Docker provider
Worth noting that eventually you might also
want to configure
Docker containers, which is also done in Docker provider config. More
about linking containers together is in Docker documentation.
Then, to add shards to the routing server, you
might use Vagrant's Shell Provisioner.
This one allows executing custom shell scripts on
the machine once it is up and running. Provided
mongo client allows inline
scripts to be run, you could use something similar
app.vm.provision "shell", inline:
'mongo --eval "sh.addShard("shard1_host:port");"'
I'm sorry, I didn't test the command above
myself, so not sure this will be working out of
the box, but this gives a general idea. (In fact,
I'm pretty sure there is something wrong with the
quotes in it :) ).
You can also create variables in the
Vagrantfile, just the same way as you would do in
any other Ruby source file, and reuse them in
order to not to repeat IPs and port numbers, for
Note that you can also run
<name of the instnance> ssh to get
the shell access into the container (provided it
is in a 'running' state), and run commands inside.
This might be useful when debugging the network
and provisioning logic.
Excuse me, I didn't test any of these ideas
with MongoDB exactly, but only with other types of
services. But I think that same principles applied
to MondoDB should work fine as well.