One local config file for both dotnet run and Docker - #113
Merged
Conversation
#112 introduced appsettings.Docker.json alongside appsettings.Development.json, which meant maintaining the same settings twice. Worse, each got its own generated signing key, so a token minted by `dotnet run` was rejected by the container and vice versa - two local environments that could not share a session. There is now one gitignored appsettings.Development.json. `dotnet run` reads it directly; compose mounts it into the container as appsettings.Docker.json, which is the name that environment loads. The environment stays Docker rather than becoming Development, because Program.cs skips UseHttpsRedirection only for Docker and the container has no HTTPS port to redirect to. Two settings cannot be shared and are overridden in compose. Neither is a secret: the database host, because inside a container localhost is the container, using the same throwaway password already spelled out on the db service; and the SMTP host, because the catcher is reachable as `mailpit` there and `localhost` here. The signing key is not among them - it stays in the file. Also publishes mailpit's 1025, so `dotnet run` can reach SMTP at the localhost:1025 the config already pointed at. Only 8025 was published before, so host-side mail went nowhere. appsettings.Development.json was tracked with only a Logging section, which is why every local change to it showed as an uncommitted diff. It is now gitignored with appsettings.Development.example.json committed as the template, matching how the Docker file was already handled, and still dockerignored so no key reaches an image layer. Verified with both running against the same file: tokens are accepted in both directions, and mail from each reaches mailpit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Yes — one file works for both. #112's separate
appsettings.Docker.jsonis gone.Why this is better than two files, not just tidier
The two files each got their own generated signing key, so a token minted by
dotnet runwas rejected by the container and vice versa — two local environments that could never share a session. One file makes the key shared by construction.Verified in both directions against the running pair:
How
dotnet runreadsappsettings.Development.jsondirectly. Compose mounts that same file into the container as/app/appsettings.Docker.json— the name that environment loads.The environment stays
Docker, notDevelopment.Program.cs:214skipsUseHttpsRedirectiononly forDocker, and the container has no HTTPS port to redirect to. Switching would have broken it.The two overrides, and why neither is a secret
ConnectionStrings__Defaultlocalhostis the container. Uses the same throwaway password already spelled out on thedbservice.Smtp__Hostmailpitthere,localhosthere.The signing key is not among them — it never leaves the mounted file, which was the original requirement.
Two things fixed on the way
Mailpit's 1025 is now published. Only 8025 was, so
dotnet runcouldn't reach SMTP at thelocalhost:1025its own config pointed at — host-side mail silently went nowhere. Both paths now deliver:appsettings.Development.jsonis no longer tracked. It was committed with only aLoggingsection, which is why every local edit to it has shown as an uncommitted diff for this entire session. Now gitignored withappsettings.Development.example.jsonas the template — matching how the Docker file was already handled — and still dockerignored, so no key reaches an image layer.Verified
Unchanged gotcha
Create
appsettings.Development.jsonbefore the firstdocker compose up. Missing file → Docker creates a directory at the mount path and the API fails on an empty connection string. Noted in the README and in a compose comment.