Support zstd compression for oci/docker image layers
Is your feature request related to a problem? Please describe.
I am currently updating my build tooling to use the dotnet SDK to build and publish containers. So far this has been excellent and easy to use.
Docker recently announced that their hardened images are now free. I attempted to use the hardened image by setting the ContainerBaseImage property in my csproj
<Project>
<PropertyGroup>
<!-- ... snip -->
<ContainerBaseImage>dhi.io/dotnet:8-alpine3.22</ContainerBaseImage>
</PropertyGroup>
</Project>
However, when my publish has ran I get the following error:
Products.EventsListener.Service net8.0 failed with 1 error(s) (2.7s)
C:\Program Files\dotnet\sdk\10.0.101\Containers\build\Microsoft.NET.Build.Containers.targets(261,5): error CONTAINER2001: Unrecognized mediaType 'application/vnd.oci.image.layer.v1.tar+zstd'.
After reviewing the code base I found the SchemaTypes class does not have the given media type - and can see two locations in code where this can cause the error to be thrown
- https://github.com/dotnet/sdk/blob/main/src/Containers/Microsoft.NET.Build.Containers/Layer.cs#L207
- https://github.com/dotnet/sdk/blob/main/src/Containers/Microsoft.NET.Build.Containers/ContentStore.cs#L53
Describe the solution you'd like
To have support added for the application/vnd.oci.image.layer.v1.tar+zstd media type so that the hardened images can be used within the container build features of the SDK.
Additional context
- Despite targeting a net8 build I am using the 10.0.100 sdk
Thanks for reporting - the underlying request here is for us to support zstd compression, so we'll have to check if this is something the Runtime supports yet. EDIT: It doesn't, I've linked this request to that issue for tracking.
There's another path we could go down here - we don't actually need to be able to decompress/compress the zstd layers, we only need to be able to download them and potentially push them elsewhere. We may be able to 'support' the consumption of zstd images just by treating the layers as opaque blobs.
The only compression mode we'd support for the layers we create for apps would be GZip, but since it's possible to mix and match layer media types this shouldn't be a problem at all.
@baronfel That is the approach I would suggest as a container ecosystem contributor/maintainer; there is nothing wrong with mixing-and-matching (though I'd encourage picking one of OCI or Docker mediaTypes for a given manifest; technically you can mix and match those too, but some tools don't handle it gracefully) mediaTypes.
Thanks for the validation @neersighted ! I've got a copilot PR out for this now that should have us compatible soon :)
though I'd encourage picking one of OCI or Docker mediaTypes
We definitely need to do some consolidation here - I think we've got an issue tracking the is already, but if not I'll get one created.
Any progress? I ran into this with <ContainerBaseImage>dhi.io/aspnetcore:10.0</ContainerBaseImage>. Strangely it works on our CI (linux/amd64) and fails locally (darwin/arm64) although both use application/vnd.oci.image.layer.v1.tar+zstd according to the platform manifests.
We use Aspire with AddProject so using a Dockerfile as alternative would technically be possible with DHI but would also mean that for publishing we need to use AddDockerfile instead.
Dotnet 11 adds support for zstd, so maybe this should be re-evaluated for 11.