Repository navigation
Closed
Labels
area/engineAbout dagger core engine
Description
Overview
This issue tracks the design and implementation status of container networking, in its various forms.
| Host-to-container (h2c) | Container-to-host (c2h) | Container-to-container (c2c) | |
|---|---|---|---|
| Use cases | Expose a service to the host |
|
|
| Status | ❌ not implemented | 🏗 in development | ✔️ #4505 |
| Notes | Will only be available for long-running containerized services, not short-lived exec |
|
Use bass c2c networking as a reference |
Design proposals
Container networking is a vast feature area. There are several ongoing proposals to design certain parts of it. Some of these proposals are compatible, while others are not.
| Proposal | c2h (tcp/udp) | h2c (tcp/udp) | c2c | c2h (unix) | h2c (unix) | status |
|---|---|---|---|---|---|---|
| Mount unix socket into exec | ❌ | ❌ | ❌ | ✅ | ❌ | Implemented |
| forwarding host TCP/UDP addresses to container | ✅ | ❌ | ❌ | ❌ | ❌ | In Discussion |
| bass-style c2c networking | ❌ | ❌ | ✅ | ❌ | ❌ | Implemented |
| “bass-plus” container networking | ✅ | ✅ | ✅ | ❌ | ❌ | Partially implemented |
Submitting a proposal
- Open a draft PR with graphql schema changes and, ideally, skeleton documentation
- Post a link to the PR in the comments to this issue. Mention which areas are covered by the proposal (c2h, h2c, c2c)
Discussing a proposal
- Comment on the relevant PR
Research material
- SSH port forwarding (
ssh -Landssh -R) - Reverse proxy configurations (nginx, apache, varnish, envoy)
- Kubernetes and Docker networking terminology
- Bass-lang networking
Reacted by Yoni Davidson, Horst Gutmann, Jordan Rash, James Qualls and Imre Hajagos
Reacted by Imre Hajagos
Metadata
Metadata
Assignees
Labels
area/engineAbout dagger core engine
Activity
sipsma commentedon Dec 2, 2022
Are we considering the container-to-host case (i.e. I want to run a dev webserver in dagger and access it from my browser) to be the same as host-to-container? In theory they are technically different (who does the connect, who does the listen), though if you do a reverse proxy thing locally then they can become the same.
Also, should probably clarify whether "container" means "exec" or "service" or both. My starting point is that we should not support serving sockets from execs and only serve them from services; execs are only able to consume them. But there's a lot to unpack and think about there so I'm far from adamant, just my first inclination.
aluzzardi commentedon Dec 2, 2022
I agree -- had some comments about that in #3691 (comment)
IF that's the case, then we don't necessarily need to mirror all calls for bind/connect.
My straw man proposal for container-to-service was to mirror host:
Regarding host-to-service (IF it's always a service), then we can have some service specific instructions:
jlongtine commentedon Dec 2, 2022
I like option 1, personally. Keeps it in code, keeps it at service "boot". The only suggestion I have is that we clarify that it is being exposed on the host, not just within the Buildkit network/context. I'm not quite sure how to do that yet, but just
Exposefeels a bit unclear to my eyes.Now that I've written that down, I'm wondering if it's possible have an API like this:
That would make pure GraphQL service queries a bit harder/uglier, but I like the clarity that would provide for the SDKs. Having said that, it seems like it will have the same issues at option 2 around messing with the shim, etc.
shykes commentedon Dec 2, 2022
vito commentedon Dec 2, 2022
+1 to starting with a distinction between services and containers for the sake of conversation.
Depending on how this goes, it might be the case that the service's container needs to be aware that it's being used as a service - via the underlying LLB we generate and/or the responsibilities of the shim - but we can cross that bridge when we get to it.
I put a bunch of details around how Bass's c2c/service networking works here: #3850 (comment)
Here are some questions based on that:
How do we want the traffic to flow in the following snippet?
Typically a client container will need to be given the address to reach as a flag/arg/env/etc. With this scheme would they just use
127.0.0.1:8080?Does that imply we have something proxying traffic between them? Are we OK with the performance hit there? The answer might simply be yes, and maybe it's a minor performance hit anyhow, but it's worth trying to think about any performance-critical use cases here. If we only care about dev/test this is probably fine. It's hard to imagine someone running e.g. a production database with Dagger since it's not really built for persistence.
Another option is to use direct c2c addressing with a bridge network (+ DNS to prevent ephemeral container IPs from busting the cache) but then we'd need to figure out how the user configures the address for the client container. We can also use DNS to avoid cache busting while keeping the proxy to solve that.
Will we implement health/liveness/readiness checks?
My take on this is the minimum viable health check is to just wait for a port to be listening, and that we should just do that by default since it's really annoying to have to manually poll for simple cases.
I don't have a strong opinion on continuous health monitoring beyond that.
@jlongtine Good question - I think we likely won't ever need to call 'expose' for container-to-container (within Buildkit network). So I think we can get away with having
Exposelive on the service and have it always mean "expose on the host" which would draw parallels to e.g. Container.Export, Directory.Export which also affect the the host.shykes commentedon Dec 6, 2022
jlongtine commentedon Dec 6, 2022
Yeah, this makes sense, @vito. I'm on board.
[-]Socket forwarding[/-][+]Tunneling[/+]shykes commentedon Dec 7, 2022
Yesterday we had a 1-1 chat with @vito that melted my brain. After sleeping on it, I am updating this issue with:
Please take a look and share your thoughts.
shykes commentedon Dec 7, 2022
Addressing a few comments and questions above:
👍 You are right, they are different and my framing was awkward. The root cause of the awkwardness was the use of the term "socket" which does actually apply to both (a socket is something you either connect or bind. then bytes are forwarded in both directions). Removing the term "socket" from feature name and API design allowed me to reconcile 1) non-confusing terminology for the thing being forwarded, and 2) non-confusing terminology for the "direction" of things.
👍 I agree also, clarified this in the issue.
For high-level discussion, it's still useful to use c2h/h2c/c2c (3 terms), instead of c2h/s2h/h2s/c2s/s2s (5 terms) :) But that's just terminology, we're all on the same page on design and implementation.
🙋🏻♂️It makes sense in theory, since we have "directory export" and "container export" which follow the same pattern.
However, I think we should not use this particular pattern here, because it is not intuitive whether the port is actually bound in the host, or simply available for ulterior service discovery from either the host or a container.
In Docker we had terminology for both: you could "expose" a port (available for service discovery), or "publish" it (bound to the host). This was generally confusing to users.
I propose a variation of this pattern that still controls the tunneling from
Service(rather thanHost), but is more explicit about what's going on.withInboundTunnelclearly means "create a tunnel that will forward inbound traffic".grouville commentedon Dec 9, 2022
With the implementation of the
WithUnixSocketprimitive, users (and myself) have started to spawn local registries to their host docker engine, using it as a long-runner engine: #4089By relying on Docker for most long-running tasks:
Host-to-container (h2c)is not as urgent asContainer-to-host (c2h). Same for theContainer-to-container (c2c), which could be workarounded by users if we had access toc2hprimitivesCurrent blockers
I am currently relying on the
WithMountedSocketsAPI for #4038.However, I am blocked by the fact that I cannot export an image (using our
coreAPI) to my private registry if it is not part of thedagger-enginenetwork. I currently have 2 options:dagger-enginenetworkI feel that the
socketimplementation tackles well the SSH forwarding issues, but theContainer-to-hostbegins to feel needed for more complex use-casesWhy am I blocked ?
We have the
hack/makemakefile that abstracts a lot of complexity and relies on Dagger-in-Dagger to build the engine. We have aengine:publishmethod that publishes to a registry, however, it doesn't work (due to above reasons) with a local registry, as we do not run the engine with the--net=hostoption when running buildkit (+ I don't think that the current architecture would allow it)From current understanding, I will have to:
3 remaining items
shykes commentedon Dec 10, 2022
[-]Tunneling[/-][+]Container networking[/+]shykes commentedon Dec 10, 2022
shykes commentedon Dec 10, 2022
sipsma commentedon Dec 10, 2022
@vito What's the input to the hash you use in bass? The LLB of the service being depended on? If so, then I'm wondering how we'd deal with sources where the LLB is stable but the actual contents can change (e.g.
image:latestor local dirs)vito commentedon Dec 12, 2022
@sipsma Bass uses the hash of the thunk, so it's a hash of the LLB "recipe" rather than the actual LLB. Thunks are fully specified - they pin image digests and don't use any other Git/HTTP LLB sources. Just images and commands.
So this is a great point. I think it would be fine to use a hash of the LLB even with unresolved references since they should be stable within that session, as long as the single session is used for running both the service and the client. This definitely relates to #3613 especially if that's not actually possible for some reason (similar to the current
Container.Exportlimitation).yonidavidson commentedon Dec 30, 2022
Adding my +1 to this feature, I would like to use this for running pre migration validations on databases and I need to spin up a MySQL DB and another container that communicates with it
sourcec0de commentedon Feb 14, 2023
I've got a few use cases for this.
Both locally and in Github actions we are able to reach these systems through tailscale.
mircubed commentedon Feb 24, 2023
@vito with #4505 merged, can you update the issue description? It looks like it wasn't updated since Dec 13th, so I want to make sure that it reflects the work that still needs to be done. Thanks!
jpadams commentedon Jul 18, 2023
@verdverm Would be great for you to outline your needs/use cases around
docker,nerdctl,podmanand container networking here. 🙏rootless, multi-os, multi-arch