惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
Google Developers Blog
博客园 - 司徒正美
J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
D
Docker
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
腾讯CDC
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
M
MIT News - Artificial intelligence
Jina AI
Jina AI
I
InfoQ
雷峰网
雷峰网
The Cloudflare Blog
美团技术团队
Engineering at Meta
Engineering at Meta

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Why Your Windows Paths Break Inside a Docker Container (a...
Iman · 2026-05-17 · via DEV Community

Iman

If you have ever deployed a .NET app inside a Docker container on a Windows host, you have probably run into a situation where a path that looks perfectly valid on the host machine causes subtle, hard-to-debug failures inside the container. This post walks through the exact problem, the runtime behaviour that causes it, and a one-line fix.


The Setup

I was building DevMetrics, a self-hosted developer productivity dashboard. Users add local Git repositories through a web form by pasting in the path. The app then calls LibGit2Sharp to scan commits from that path.

On Windows, running via dotnet run, everything worked fine. After dockerizing the app and running it as a Linux container, paths started silently mangling themselves.


The Symptom

A user pastes this into the form:

D:\Users\Downloads\my-project

Enter fullscreen mode Exit fullscreen mode

The app logs show the path it actually tried to open:

/app/D:\Users\Downloads\my-project

Enter fullscreen mode Exit fullscreen mode

The working directory /app had been prepended to the Windows path. LibGit2Sharp then throws because that path obviously does not exist.


Why It Happens

The culprit is Path.GetFullPath. In .NET, calling GetFullPath on a relative path resolves it against the current working directory. The relevant question is: what counts as "rooted" on Linux?

// On Windows: returns true
Path.IsPathRooted("D:\\Users\\Downloads\\my-project");

// On Linux: returns FALSE
Path.IsPathRooted("D:\\Users\\Downloads\\my-project");

Enter fullscreen mode Exit fullscreen mode

Linux has no concept of Windows drive letters. To the Linux runtime, D:\Users\Downloads\my-project is not an absolute path starting with a drive letter. It is a relative path that happens to start with the character D.

So when you call:

Path.GetFullPath("D:\\Users\\Downloads\\my-project")

Enter fullscreen mode Exit fullscreen mode

on Linux, the runtime treats it as relative and prepends the process working directory, giving you /app/D:\Users\Downloads\my-project.

No exception is thrown. No warning is logged. The path just silently becomes wrong.


The Fix

Guard with IsPathRooted before calling GetFullPath:

private static string NormalisePath(string path)
{
    var trimmed = path.Trim();

    var absolute = Path.IsPathRooted(trimmed)
        ? trimmed
        : Path.GetFullPath(trimmed);

    return absolute.TrimEnd(
        Path.DirectorySeparatorChar,
        Path.AltDirectorySeparatorChar);
}

Enter fullscreen mode Exit fullscreen mode

If IsPathRooted returns false (which it will for any Windows-style path on Linux), skip GetFullPath entirely and use the trimmed value as-is. The path will still be wrong in the sense that D:\... is not a valid Linux path, but at least you have not silently corrupted it further. You can then validate it properly and return a clear error to the user.


The Deeper Problem: Host Paths vs Container Paths

Even with the fix above, there is a second issue worth understanding. When you run Docker on Windows, the paths inside the container are Linux paths, not Windows paths.

If your docker-compose.yml mounts a host directory like this:

volumes:
  - D:\Users\Downloads\my-project:/repos/my-project

Enter fullscreen mode Exit fullscreen mode

Inside the container, that directory is available at /repos/my-project. The Windows path D:\Users\Downloads\my-project does not exist from the container's perspective at all.

So the correct path for a user to enter in your app's form is /repos/my-project, not the Windows path they see in File Explorer.

This is worth making explicit in your UI. In DevMetrics I added a hint directly on the Add Repository form:

In Docker, use the container path (e.g. /repos/my-project).

A one-line hint that prevents a lot of confusion.


The rule is simple: IsPathRooted is OS-aware. A Windows drive-letter path is not considered rooted on Linux, and GetFullPath will silently corrupt it as a result.