Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup multi-host networking with docker swarm on multiple remote machines

Before asking this question I have read quiet of articles and stackoverflow questions but I couldn't get the right answer for my setup(perhaps it is already answered). Here is the architecture I have been struggling to get it to work.

  1. I have three physical machines and I would like to setup the Docker swarm with multi-host networking so that I can run docker-compose.

For example:

  1. Machine 1(Docker Swarm Manager and Contains Consoul)(192.168.5.11)
  2. Machine 2(Docker Swarm Node)(192.168.5.12)
  3. Machine 3 (Docker Swarm Node)(192.168.5.13)

And I need to run docker-compose from any other separate machine.

I have tried Docker article but in that article it is all setup under the same physical machine using docker-machine and virtual box. How can I achieve above in three remote machines. Any help appreciated.

like image 429
Akram Yakubov Avatar asked Oct 18 '25 15:10

Akram Yakubov


1 Answers

The latest version of Docker has Swarm Mode built in, so you don't need Consul.

To set up on your boxes, make sure they all have docker version of 1.12 or higher and then you just need to initialise the swarm and join it.

On Machine 1 run:

docker swarm init --advertise-addr 192.168.5.11

The output from that will tell you the command to run on Machine 2 and 3 to join them to the swarm. You'll have a unique swarm token, and the command is something like:

docker swarm join \
--token SWMTKN-1-49nj1... \
192.168.5.11:2377

Now you have a 3-node swarm. Back on Machine 1 you can create a multi-host overlay network:

docker network create -d overlay my-app

And then you run workloads in the network by deploying services. If you want to use Compose with Swarm Mode, you need to use distributed application bundles - which are currently only in the experimental build of Docker.

like image 172
Elton Stoneman Avatar answered Oct 20 '25 10:10

Elton Stoneman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!