microsoft/aspire · error · InvalidOperationException
Bind mounts are not supported by the Kubernetes publisher
Error message
Bind mounts are not supported by the Kubernetes publisher
What it means
Thrown by ProcessVolumes in KubernetesResource when a container mount has type BindMount. Bind mounts reference host filesystem paths, which do not translate to Kubernetes manifests; the publisher only supports named volumes mounted via VolumeMountV1.
Solutions
- Replace the bind mount with a named volume via WithVolume(volumeName, targetPath)
- Use a Kubernetes persistent volume/claim through a resource customization annotation if persistent storage is required
- Guard the mount with a runtime-vs-publish check so bind mounts only apply during F5/run mode
Example fix
// before
var db = builder.AddPostgres("db").WithDataBinding("./pgdata");
// after
var db = builder.AddPostgres("db").WithDataVolume(); Defensive patterns
Strategy: validation
Validate before calling
if (mount.Type == ContainerMountType.BindMount) throw new InvalidOperationException("Replace bind mounts with named volumes for Kubernetes publishing"); Try / catch
try { PublishAsync(...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Bind mounts are not supported")) { /* convert to named volume */ } Prevention
- Use WithDataVolume()/named volumes instead of host paths
- Gate bind mounts behind run-mode-only code paths
- Add a publish-mode integration test that enumerates mounts
When it happens
Trigger: Calling WithVolume(sourceHostPath, targetPath) or any API that creates a ContainerMountType.BindMount on a resource, then publishing with the Kubernetes publisher.
Common situations: Local dev workflows that bind-mount host directories (e.g. './data:/data') and are then published to Kubernetes without switching to named volumes or PVCs.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Kubernetes persistent volume
- Resource ' ' cannot resolve the ' ' persistent-volume path…
- Resource ' ' is assigned to compute environment ' ' but…
- Resource ' ' binds different Kubernetes persistent volumes…
- Unsupported storage type
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/d028331096f6aea0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Kubernetes/KubernetesResource.cs:310
}
private void ProcessVolumes()
{
if (!resource.TryGetContainerMounts(out var mounts))
{
return;
}
foreach (var volume in mounts)
{
if (volume.Source is null || volume.Target is null)
{
throw new InvalidOperationException("Volume source and target must be set");
}
if (volume.Type == ContainerMountType.BindMount)
{
throw new InvalidOperationException("Bind mounts are not supported by the Kubernetes publisher");
}
var newVolume = new VolumeMountV1
{
Name = volume.Source,
ReadOnly = volume.IsReadOnly,
MountPath = volume.Target,
};
Volumes.Add(newVolume);
}
}
#pragma warning disable ASPIREPROBES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
private void ProcessProbes()
{
if (!resource.TryGetAnnotationsOfType<ProbeAnnotation>(out var probeAnnotations))
{View on GitHub (pinned to 25830f84bd)