Build docker in ASP.NET Core: "no such file or directory" error

It's happening because you didn't published your solution. The error message is self-explanatory:

no such file or directory

By default, when you add Docker support to you ASP.NET Core Visual Studio 2017 project, it creates a bunch of docker-compose.yml files, one of them is docker-compose.ci.build.yml which handles the build process. Then, when you build the project through Visual Studio, full docker-compose pipeline is executed.

The contents of docker-compose.ci.build.yml, are similiar to this (it depends on custom config and project names obviously):

version: '2'

services:
  ci-build:
    image: microsoft/aspnetcore-build:1.0-1.1
    volumes:
      - .:/src
    working_dir: /src
    command: /bin/bash -c "dotnet restore ./SolutionName.sln && dotnet publish ./SolutionName.sln -c Release -o ./obj/Docker/publish"

As you can see in the last line, there is a dotnet publish command invoked, which actually builds & publishes your project.

So the solution for your issue, will be just building the project before calling docker:

dotnet publish ./SolutionName.sln -c Release -o ./obj/Docker/publish
docker build -t my-docker-image-test .

When you use the option "Add Docker Support" in Visual Studio 2017, VS generates a bunch of docker-compose files and Dockerfiles. As Marcin Zablocki mentioned, one of these is docker-compose.ci.build.yml.

To stay in line with the Docker philosophy, you can use a docker container to publish your project. To publish your project you would take the following steps:

  1. git clone/pull your project & cd into the root dir
  2. Publish your project with docker-compose -f docker-compose.ci.build.yml up
  3. Start your project with docker-compose up

I have encountered situations where the Dockerfile of your main project is giving problems. This happens with FROM microsoft/aspnetcore:1.1, you can change it to FROM microsoft/aspnetcore:1.1.2 or whatever version is needed for your project.