aspire icon indicating copy to clipboard operation
aspire copied to clipboard

AddContainer fails cryptically if a fully qualified image name is used

Open afscrome opened this issue 9 months ago • 1 comments

If you're familiar with docker, you may try to do one of the following

var redis= builder.AddContainer("redis", "redis:latest");
var sql = builder.AddContainer("sql", "mcr.microsoft.com/mssql/server:2022-latest");

Both of these will be accepted by the app host builder, but will then fail with a cryptic error later on:

could not create the container    {"Container": {"name":"reds"}, "Reconciliation": 3, "error": "CreateContainer command returned error code 1 Stdout: '' Stderr: 'invalid reference format\n'"}

This is because aspire expects the registry, image and tag to be provided separately i.e.

var redis = builder.AddContainer("redis","redis", "latest");
var sql = builder.AddContainer("sql", "mssql/server", "2022-latest").WithImageRegistry("mcr.microsoft.com");

This seems like an easy mistake for users familiar with docker to make. This could be improved by either:

  1. Fail fast if a fully qualified reference is provided to AddContainer(string, string) (i.e. does the string contain : or .)
  2. Accept a fully qualified reference in AddContainer(string, string)

afscrome avatar May 17 '24 20:05 afscrome