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

Resolve the correct container runtime and chose appropriate host name #2639

Closed
thangchung opened this issue Mar 5, 2024 · 11 comments · Fixed by #3038
Closed

Resolve the correct container runtime and chose appropriate host name #2639

thangchung opened this issue Mar 5, 2024 · 11 comments · Fixed by #3038
Assignees
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Comments

@thangchung
Copy link

When I tried to run AddPostgres with WithPgAdmin as well as AddRedis with WithRedisCommander, nothing worked on Podman native.

I struggled to find the root cause and finally found the problem when I ran:

> podman ps
> podman exec -it <pg admin container id> sh
> cat servers.json
{"Servers":{"1":{"Name":"postgreSQL","Group":"Aspire instances","Host":"host.docker.internal","Port":5432,"Username":"postgres","SSLMode":"prefer","MaintenanceDB":"postgres","PasswordExecCommand":"echo \u0027<password>\u0027"}}} 

Look at the Host, it still pointed to host.docker.internal although I run on Podman. And the same thing happened to Redis with RedisCommander And I think this is a bug.

OS: Windows 11
.NET 8.0.200
.NET Aspire version: 8.0.0-preview.4.24127.7+2cbacd4bf15147d0ce67e915f6932bffb3f7e720
Podman version: 4.9.0

/cc @davidfowl

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 5, 2024
@davidfowl davidfowl added bug and removed untriaged labels Mar 5, 2024
@davidfowl davidfowl added this to the preview 4 (Mar) milestone Mar 5, 2024
@davidfowl davidfowl self-assigned this Mar 5, 2024
@davidfowl
Copy link
Member

davidfowl commented Mar 5, 2024

@danegsta Is there a way to query the container runtime from dcp?

Seems like we should be using host.containers.internal for podman. We have a configurated based override in other places but it seems like these are hardcoded:

var hostString = $"{(hostsVariableBuilder.Length > 0 ? "," : string.Empty)}{redisInstance.Name}:host.docker.internal:{redisInstance.PrimaryEndpoint.Port}:0";

context.EnvironmentVariables.Add("PMA_HOST", $"host.docker.internal:{endpoint.Port}");

writer.WriteString("Host", "host.docker.internal");

context.EnvironmentVariables.Add("ME_CONFIG_MONGODB_URL", $"mongodb://host.docker.internal:{resource.PrimaryEndpoint.Port}/?directConnection=true");

@DamianEdwards
Copy link
Member

We'll need this exposed in the app model during lifecycle callbacks to allow other resources to do this too.

@karolz-ms
Copy link
Member

@davidfowl we have this thing called DcpDependencyCheck that is run as part of DcpHostService startup. It gathers the information about container runtime. I am not sure if the result of the check is readily available to the callbacks, but it should be pretty easy to make it available.

@karolz-ms
Copy link
Member

IDcpDependencyCheckService is already part of the DistributedApplicationBuilder https://github.com/dotnet/aspire/blob/main/src/Aspire.Hosting/DistributedApplicationBuilder.cs#L95

@davidfowl
Copy link
Member

It’s not currently not those callbacks run a bit too early today. If we have the information then we can figure out how to make it work.

@danegsta
Copy link
Member

danegsta commented Mar 5, 2024

We do provide the identified runtime from DCP as part of those dependency checks, but something to consider is that there are ways to bind a custom local machine address in a container if we wanted to make this work consistently across runtimes.

@davidfowl
Copy link
Member

I'm going to do a cheap fix for preview 4 to make this configurable. We have this same problem in other parts of the stack but it's centralized. I'm going to make this use the same logic. In preview 5, we can make it more automatic based on the container runtime.

@davidfowl
Copy link
Member

PR is up. It will still require manual work for preview4, we'll make it more automagic in p5.

@davidfowl
Copy link
Member

We do provide the identified runtime from DCP as part of those dependency checks, but something to consider is that there are ways to bind a custom local machine address in a container if we wanted to make this work consistently across runtimes.

Lets' chat about doing this @danegsta

@karolz-ms
Copy link
Member

I am a little surprised that host.docker.internal did not work with Podman. These PRs should have enabled it, if I understand things correctly: containers/common#1592 and containers/common#1549

@davidfowl
Copy link
Member

@karolz-ms that PR adds host.containers.internal it seems.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants