HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerMinor

Join a Linux Docker swarm with a local Windows Docker for test purposes

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
swarmlocaldockerwithjoinforlinuxwindowstestpurposes

Problem

I'm currenlty trying to connect/join a Linux Docker Swarm cluster with my Windows machine in order to test a stack without sending the stack over and over to my test cluster under Linux. My problem is that I can't join the cluster with my Windows Docker.

My cluster had initially 1 manager and 4 workers. I recently created and added a new manager to it in order to add my Windows Docker node as manager. With this, I shouldn't have any issue with the manager quorum (since my two managers will be always up, and my Windows Docker could be interrupted at any time).

I configured my local firewall - and also on each nodes of my Linux cluster - to accept connections on ports (the following can be found at the end of this documentation) :

  • TCP port 2377 for cluster management communications



  • TCP and UDP port 7946 for communication among nodes



  • UDP port 4789 for overlay network traffic



The advertising network in my cluster is 192.168.0.0/24, one of my manager's IP address is 192.168.0.100 and my PC's IP address is 192.168.0.143 (same network). They can ping each others and I tested the ports defined before.

So, when I perform the docker swarm join-token manager on a manager I have something like this:

docker swarm join --token SWMTKN-1-27hzpcnek5... 192.168.0.200:2377


If I copy/paste it to my PC:

Error response from daemon: manager stopped: can't initialize raft node: rpc error: code = Unknown desc = could not connect to prospective new cluster member using its advertised address: rpc error: code = DeadlineExceeded desc = context deadline exceeded


But, even with this error, on my cluster, if I run docker node ls, my node appears in the list:

8380zb5jeke0elwohr7aieke8     linuxkit-00155d00d946   Ready               Active


But on my PC Docker thinks that it's not member of a cluster:

```
Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and

Solution

Why do you want to create a new Manager node, risking damaging your raft consensus and cie?

I find it way easier to simply expose the docker socket locally, as if you were working inside the node, but with your Windows environment.

To do so, simply open a ssh tunnel that exposes /var/run/docker.sock:

ssh -M -S ~/.docker.sock \
     -fnNT -4 -L localhost:1337:/var/run/docker.sock \
     USER@MANAGER_IP


Refer to man ssh to see what all these options mean.

It will open an ssh tunnel; you will still be in your local environment shell, only thing left to do is set the proper DOCKER_HOST environment var, so your docker cli is bound to your swarm manager.

export DOCKER_HOST=localhost:1337

And that's it.

Note: Docker also includes an option to do this; I've quickly searched for it but can't manage to find it. It's in the most recent version of docker.

Code Snippets

ssh -M -S ~/.docker.sock \
     -fnNT -4 -L localhost:1337:/var/run/docker.sock \
     USER@MANAGER_IP

Context

StackExchange DevOps Q#4161, answer score: 2

Revisions (0)

No revisions yet.