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.

addDS

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
WORKDIR /app
EXPOSE 80
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

*
!obj/Docker/publish/*
!obj/Docker/empty/

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.

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: