TCP Services in Docker Swarm Cluster

I'm trying to find out how to create a TCP service in a docker Swarm environment and I cannot find any working example; also the docs don't show anything useful there.

Is anyone able to show me a working example for MySQL, IMAP, or any other TCP service that they deployed as stack and really floats the traffic ?

It would be great to see and test to make TCP more understandable in Swarm environments if possible.

Do you want plain TCP passthrough or use Traefik to terminate TLS/SSL first?

Both examples would be great!

Here is a simple Traefik TCP example with Traefik LetsEncrypt TLS TCP and plain TCP. When using in Docker Swarm, move the labels under deploy section.

1 Like

This is a great example, thanks a lot! In my first "opinion" I'm doing (quite) the same so this is very good to reference where I go wrong.

I let you know when I know (more) :wink:

@bluepuma77 OK, I see the start of the problem; none of the services is deployed, also not Traefik.

I think it goes wrong there.

@bluepuma77 Do you have any thoughts about deployments per service on swarm in this case ?

What do you want to achieve? What is your issue?

When using with Swarm, just add deploy sections to each service and move labels below.

Then use docker stack deploy.

It's probably best to use an "external" Docker overlay network with all services.

That is exactly what I do but TCP routers are not recognized by Traefik then.

Make sure to enable docker.swarmMode and have the Traefik container constraint to Docker Swarm manager node, only there it can get all required information about the services.

Note that Traefik v3 has moved to a new swarm provider.

swarmMode is set to true, I do need to the manager node(s) ? I need to test that indeed.

V3 is not what I have tested yet, what changed for this setup if I may ask ? First V2 working then the rest!

Thanks so far!

Check docs, don’t forget target port label which is also needed for Swarm.

OK, will do (again)! I will report back what happens!