I apologize in advance for the length - but this is interesting, especially for architects and traefik wizards.
The bottom line is, I'm hoping that there's a setup in which we can leverage traefik
s dynamic config capability to:
detect automatically when a container is stopped, and know to fallback to external services on developer machine / external host.
Alternatively - when a local-db container is started, know to prefer it over db service from external source.
I need to optimize a workflow for a couple of teams.
This requires to run on developer machine the absolute minimum required.
Current solution relays on docker-compose and traefik@1.x
, and I'm asked to preserve this, however, I believe upgrading to traefik@2.x
would be accepted.
I'm actually pursuing with you here two use-cases, which I believe have the same solution - at least in theory...
Dev-Mode = running a process in debug mode, with IDE, file-watch live reloads, etc.
AS A - developer of services in mid layers of the service mesh
I WANT - to be able to direct traffic to services under development to
native processes on my machine, and keep the rest in the compose
network
SO THAT - I can run in Dev-Mode only services under development,
while all the rest in the mesh run using production-level docker
images in docker-compose.
AS A - developer of data brokers in the mesh
I WANT - to control if containers get to the shared db or to local
db container using traefik
SO THAT - I can keep applications in the containers completely agnostic to
the topography in which they run
As a start - Since Traefik is the service-buss through which all inter-container communications pass - I'm looking for a way to configure traefik
to consume services from outside the docker-compose network.
The first use-case means to use traefik
as the service buss - the sole entity that knows where each service runs, which could be a container, or a service external to the docker-compose network.
The second use-case means to setup traefik
to direct traffic to a process runs outside the docker-compose network, but specifically on the developer's machine, which in turn, consumes services from the compose network (for this, the dev compose, unlike production compose - exposes an entrypoint for each node in the mesh, including for services that are consumed only internally on production).
I know there are two questions here, but I could not think of another way to ask each question separately and get answers relevant to the full picture...
I'm hoping that there's a setup in which we can leverage traefik
s dynamic config capability to:
detect automatically when a container is stopped, and know to fallback to external services on developer machine or any other host for the matter. Alternatively - when a db container is started, knows to prefer it over external db service.
We can ask developers to add records to their hosts
file, but a DNS-based solution would be much preferred, especially if we can use the DNS built-in to docker :)
Any help or point to the right direction would be very appreciated!
I've done it.
Check out the solution in isolation demonstrated here:
https://github.com/osher/lcdev-using-compose-and-traefik
TL;DR:
host.docker.internal
.The result:
traefik
will try the developer machine.