Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable container-to-container service communication #5628

Merged
merged 20 commits into from
Sep 12, 2024

Conversation

danegsta
Copy link
Member

@danegsta danegsta commented Sep 9, 2024

Description

This PR implements a custom container network for an Aspire AppHost run and uses it to support direct container-to-container service communication without going through service proxies on the host. This should allow scenarios such as sidecar management containers to work with more container runtime environments. For now we're hardcoding container-to-container connections in individual sidecar resources until we design and implement an updated API for connection service discovery that can better support these scenarios.

Fixes #5584

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
      • Link to aspire-docs issue:
    • No
Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Sep 9, 2024
@davidfowl davidfowl marked this pull request as ready for review September 10, 2024 20:57
@davidfowl
Copy link
Member

davidfowl commented Sep 10, 2024

Errors here:

 Expected: myredis1:host.containers.internal:5001:0
[xUnit.net 00:00:05.16]       Actual:   myredis1:myredis1:6379:0

We need to update host names in the tests

@davidfowl
Copy link
Member

Now the port is wrong 😄

@davidfowl
Copy link
Member

Beyond the small changes to ports and host names, it seems like using the docker network slows down the startup of these containers or breaks logs in some way that causes tests to fail.

@@ -208,7 +204,7 @@ public async Task MultipleRedisInstanceProducesCorrectRedisHostsVariable(string
DistributedApplicationOperation.Run,
TestServiceProvider.Instance);

Assert.Equal($"myredis1:{containerHost}:5001:0,myredis2:host2:5002:0", config["REDIS_HOSTS"]);
Assert.Equal($"myredis1:{redis1.Resource.Name}:6379:0,myredis2:myredis2:6379:0", config["REDIS_HOSTS"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why these ports are changing for these tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container to container requires using the in-container target port instead of the public port for connections

@mitchdenny
Copy link
Member

mitchdenny commented Sep 12, 2024

With the container network creation, is this something that might benefit from being persistent by default? What I'm thinking is that if we made it persistent it would allow developers to spin up containers manually and attach it to that network if they want to.

@mitchdenny
Copy link
Member

mitchdenny commented Sep 12, 2024

Is now a good time to discuss Podman testing? At the moment all of our testing is done against Docker/Docker Desktop, but we say we support Podman but don't do any validation in our CI.

It shouldn't block our PR, I'll raise an issue for it specifically.

@danegsta
Copy link
Member Author

With the container network creation, is this something that might benefit from being persistent by default? What I'm thinking is that if we made it persistent it would allow developers to spin up containers manually and attach it to that network if they want to.

Long term I think it may be cleaner to work out how we want to expose container networks as a primitive in the resource builder API and allow users to configure their networks (including persistent networks to support this container attach scenario) that way.

@danegsta
Copy link
Member Author

My main concern is that the V1 approach in this PR is taking an extremely naive approach that depends on a lot of assumptions that could fall apart if we allow non-Aspire managed containers to attach to the network. Depending on tightly managed AppHost scoped networks makes the assumptions a bit more reasonable.

@davidfowl
Copy link
Member

Other failures are gone! Thanks for the bug fix in dcp @danegsta!

@radical the failure is:

docker command 'CreateContainer' returned with non-zero exit code 1: command output: Stdout: '' Stderr: 'Unable to find image 'netaspireci.azurecr.io/library/mongo-express:1.0' locally\nError response from daemon: manifest for netaspireci.azurecr.io/library/mongo-express:1.0 not found: manifest unknown: manifest tagged by "1.0" is not found

How do we get container images on our test feed?

@radical
Copy link
Member

radical commented Sep 12, 2024

@radical the failure is:

docker command 'CreateContainer' returned with non-zero exit code 1: command output: Stdout: '' Stderr: 'Unable to find image 'netaspireci.azurecr.io/library/mongo-express:1.0' locally\nError response from daemon: manifest for netaspireci.azurecr.io/library/mongo-express:1.0 not found: manifest unknown: manifest tagged by "1.0" is not found

I can add this one.

How do we get container images on our test feed?

https://github.com/radical/aspire/blob/tests-run-scripts/docs/updating-container-registry.md

@radical
Copy link
Member

radical commented Sep 12, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidfowl davidfowl merged commit 4eeea45 into dotnet:main Sep 12, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Container to container networking issues with podman and vanilla docker engine
5 participants