I have a custom SQL Server Docker image which I would like to add to my Aspire project. The image exposes port 1433. How do I bind that to an endpoint assigned by Aspire? I plan on adding other containers in a similar way that have nothing to do with SQL Server once I get this working.
Configuring it like this runs the container but does not bind the port from the endpoint:
builder.AddContainer("custom-sql-container", "my.sql.image")
       .WithEndpoint(1433, 1433);
I was looking at the container in docker desktop, where it was not showing a bound port at all:

But docker ps gave me this spicy little nugget:

So it is binding the port, just not to what I expected it to be. Does this mean that aspire just hasn't set up a proxy for that port or do I just completely misunderstand how this is supposed to be configured?
I know this is a bit late, but I thought I would post this here as I spent a lot of time trying to figure this out.
I had a very similar issue with sqlserver. and wanting to connect with ssms i added this:
var sql = builder
    .AddSqlServer("sql", password)
    .WithLifetime(ContainerLifetime.Persistent)
    .WithDataBindMount(source: @"C:\SqlServer\Data")
    .WithEndpoint(port:6033, targetPort:1433, name:"ssms")
    .WithContainerName("sqlserver");
now I can connect with 127.0.0.1,6033 with my username and password.
SQL Server will, by default, only listen for connections on the loopback interface [127.0.0.1] or [0.0.0.0]. That means even ports that are EXPOSED to an endpoint that has been assigned by Aspire, any external connections trying to reach your SQL Server Instance will not be able to find it.
Resolution: You could use 127.0.0.1 (not "localhost") as the host name in the connection strings used to connect to the instance of SQL Server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With