liveBook · Manning

Volume

As explained in .NET in Action, Second Edition

A volume is storage made available to a container by mounting a host folder or file at a path in the container.

A volume makes a host folder or file available inside a container at a chosen path. It provides a practical way to supply external configuration and secrets without embedding them in the image. section 13.5

When using volumes for configuration, keep these runtime behaviors in mind:

  • Mount a target folder separate from existing image content, because the mount can overwrite files already there. section 13.5
  • Read mounted JSON with an optional configuration source, such as /settings/secrets.json. section 13.5
  • Use mounted volumes to keep secrets separate from ordinary application configuration. section 13.6
Listing 13.24 Adding optional file configuration source
builder.Configuration.AddJsonFile(
  "/settings/secrets.json",                              #1
  optional: true);                                       #2
  
builder.Services.Configure<CosmosDbSettings>(            #3
  builder.Configuration.GetSection("CosmosDbSettings"));
  
var app = builder.Build();

Adds an optional JSON configuration source for a secrets file mounted at /settings/secrets.json. section 13.5

How .NET in Action, Second Edition covers it

How deep it goes
Explains mounting, overwrite behavior, and JSON consumption, but does not detail Docker volume commands.
Examples
Uses a mounted secrets.json file at /settings/secrets.json to provide CosmosDbSettings:AuthKey.
What you can do after
Operate/configure Docker mounts and consume mounted JSON secrets through ASP.NET Core configuration.
How it connects
Connects volumes with containers, Docker, configuration, secrets, and the options pattern.

Also explained in

Compare how 8 books explain volume →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.