COPY failed when adding files to Docker container

This is a blogpost for myself. Because I don’t want to make the same stupid mistake again. And hopefully It might help you as well …

I was preparing a demo to build a simple Docker Container. I used Visual Studio 2017 15.3 to create a new .NET Core Project, to which I added Docker Support.


This gives me a Docker File within the .NET Core project and a Docker Project with some Docker-Compose files. But for reasons of simplicity I just wanted to build a Docker container with a published app, without the Docker-compose “magic”.

The idea is to build and publish from the command line and then build the container with the published files.

dotnet restore
dotnet publish -o ./coolapp

These commands gave me a published dotnet app which I can copy into the container

I took the Dockerfile that was generated and transformed it to something simple

FROM microsoft/aspnetcore:1.1
COPY ./coolapp .
ENTRYPOINT ["dotnet", "VotingApp-Net.dll"]

Then I ran the docker build command

docker build -t rvo/testapp .

and then I got an error

COPY failed: stat /var/lib/docker/tmp/docker-builderXXXX/coolapp: 
no such file or directory

When using the Docker compose files, dotnet publish, publishes to obj/Docker/Publish. When I copied my files there, and pointed my Dockerfile to this directory (as generated), it works…

After some digging I found the issue why files are not found. Visual Studio also generated a .dockerignore file that contains the following


That explains why files are not found. They are ignored. When I cleared this file (or exclude the dir I want to add), it works fine !

Note to self: Never forget the ignore file.

One Response to “COPY failed when adding files to Docker container”

  1. Got the same issue. Spent an hour trying to find out why Docker didn’t see my files.
    Thank you for the post!

%d bloggers like this: