Access Container from other Container does not work in Preview3 #2677
-
I want to connect a custom container (in private ACR) to a RabbitMQ. using Aspire.Hosting;
var builder = DistributedApplication.CreateBuilder(args);
var rabbitMq = builder.AddRabbitMQContainer2("messaging", port: 5672, password: "guest")
.WithEnvironment("RabbitMQEventBus:UserName", "guest")
.WithEnvironment("RabbitMQEventBus:Password", "guest")
.WithEnvironment("RabbitMQEventBus:ExchangeName", "myexchange")
.WithVolumeMount("../../deploy/DockerCompose/Local/RabbitMQ/docker-entrypoint.sh", "/usr/local/bin/docker-entrypoint.sh");
var my_custom_app= builder.AddContainer(name: "my_custom_app",
image: "crhocustom.azurecr.io/my_custom_app",
tag: "7.7.0-ft_feature")
.WithEnvironment("RabbitMQEventBus__Connections__0__HostName", "host.docker.internal");
.WithReference(rabbitMq)
.WithEndpoint(containerPort: 80, hostPort: 5092, name: "endpoint", scheme: "http"); AddRabbitMQContainer2 methode : /// Adds a RabbitMQ container to the application. The default image name is "rabbitmq" and the default tag is "3-management".
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param>
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param>
/// <param name="port">The host port of RabbitMQ.</param>
/// <param name="password">The password for RabbitMQ.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<RabbitMQContainerResource> AddRabbitMQContainer2(this IDistributedApplicationBuilder builder, string name, int? port = null, string? password = null)
{
password ??= Guid.NewGuid().ToString("N");
var rabbitMq = new RabbitMQContainerResource(name, password);
return builder.AddResource(rabbitMq)
.WithAnnotation(new EndpointAnnotation(ProtocolType.Tcp, port: 5672, containerPort: 5672, name : "amqp"))// , isExternal: true
.WithAnnotation(new EndpointAnnotation(ProtocolType.Tcp, uriScheme: "http", name: "management", port: null, containerPort: 15672))
.WithAnnotation(new ContainerImageAnnotation { Image = "rabbitmq", Tag = "3-management" })
.WithManifestPublishingCallback(context => WriteRabbitMQContainerToManifest(context, rabbitMq))
.WithEnvironment("RABBITMQ_DEFAULT_USER", "guest")
.WithEnvironment(context =>
{
if (context.PublisherName == "manifest")
{
context.EnvironmentVariables.Add("RABBITMQ_DEFAULT_PASS", $"{{{rabbitMq.Name}.inputs.password}}");
}
else
{
context.EnvironmentVariables.Add("RABBITMQ_DEFAULT_PASS", rabbitMq.Password);
}
});
}
can you help me ? |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
What do the logs say? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Can you print the address that the container is using in the logs? |
Beta Was this translation helpful? Give feedback.
-
It's unclear what might be happening, but there is a proxy forwarding tcp traffic to the container. I do recommend reading this https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/networking-overview. |
Beta Was this translation helpful? Give feedback.
-
the problem seems to be linked to the "bridge" mode and the fact that the containers are not in the same network (as one could do on docker-compose). If I start the same container manually, I reproduce the same problem.
The --link command seems to be deprecated on docker and replaced by the use of network. How to use a dedicated network or add the --link between AddContainer(...) on Aspire ? |
Beta Was this translation helpful? Give feedback.
-
There's no API support to go container to container in aspire. It's all through the host. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the responsiveness 🙂 So container cannot use the services exposed by the proxy? Another use case would be to be able to debug APIs used by a mobile application (Xamarin or Kotlin). This will be impossible as long as the App.Host remains accessible only from the workstation (localhost) |
Beta Was this translation helpful? Give feedback.
-
It can by substituting |
Beta Was this translation helpful? Give feedback.
-
Yes, in effect. You are right @DamianEdwards and @davidfowl ! => however, I still have the problem exposing the services started by Aspire on the IP of my workstation In any case, great project! THANKS 💪🚀 |
Beta Was this translation helpful? Give feedback.
It can by substituting
localhost
forhost.docker.internal