You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows容器指定文件无法找到及/app目录缺失问题求助

Hey there! No worries at all—we all start somewhere with Docker, and this is a super common gotcha. Let’s break down what’s happening here.

Why the /app directory isn’t showing up

The root issue here is almost certainly that your COPY dist /app instruction didn’t actually create the /app directory in the image. Here are the most likely reasons:

  • Your local dist directory is empty or doesn’t exist
    Docker’s COPY command only creates the target directory if there’s content to copy into it. If your local dist folder is empty, or you’re running docker build from a directory where dist doesn’t exist, Docker won’t create the /app directory at all. That’s why docker diff doesn’t show it, your docker cp command fails, and you get the startup error (the container can’t find ExampleApp.dll because /app doesn’t exist).

  • You’re mixing Linux and Windows container modes
    The mcr.microsoft.com/dotnet/core/aspnet:3.1 image defaults to a Linux-based image. If you’re running Docker in Windows Container mode on your machine, this causes path mismatches. Windows containers use backslash paths (like C:\app) instead of forward slashes (/app), so setting WORKDIR /app points to a non-existent path relative to the current drive.

How to fix this

Let’s walk through the steps to resolve this:

1. Make sure your dist directory has content

First, generate the published files for your .NET app if you haven’t already. Run this in your local project directory:

dotnet publish -c Release -o dist

This creates a dist folder with all necessary files (including ExampleApp.dll).

2. Build your image correctly

Navigate to the folder where your Dockerfile lives (it should be in the same parent directory as your dist folder), then run:

docker build -t exampleapp .

The . at the end tells Docker to use the current directory as the build context, so it can find the dist folder.

3. Match your container mode to the base image

  • If you want to use Linux containers (default for this .NET image), open Docker Desktop > Settings > General and ensure "Use the WSL 2 based engine" is enabled.
  • If you prefer Windows containers, switch Docker to Windows mode and update your Dockerfile to use a Windows-specific base image and paths:
    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1909
    COPY dist C:\app
    WORKDIR C:\app
    EXPOSE 80/tcp
    ENTRYPOINT ["dotnet", "ExampleApp.dll"]
    

4. Verify the directory exists

After building the corrected image, run a temporary container to check if the directory has your files:

# For Linux containers
docker run --rm exampleapp ls /app

# For Windows containers
docker run --rm exampleapp dir C:\app

This should list ExampleApp.dll and other published files. If it does, your docker cp command will work once you start a container from this image.

Bonus debugging tips

  • Always check the output of docker build—if there’s an error about missing dist, that’s your immediate clue.
  • Get an interactive shell inside the image to explore the filesystem directly:
    # Linux containers
    docker run --rm -it exampleapp bash
    
    # Windows containers
    docker run --rm -it exampleapp cmd
    

内容的提问来源于stack exchange,提问作者whoisit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 14:22:28