VS 2019 Container Application for Kubernetes errors received when deploying with Azure DevOps Pipeline

1/9/2020

I created a Container Application for Kubernetes in Visual Studio as follows:

enter image description here

Docker file looks like this:

enter image description here

Result from running in Powershell with success:

enter image description here

I tried using the pipeline template - Deploy to Azure Kubernetes Service:

enter image description here

I used the YAML "as-is":

enter image description here

When I save and run, I get the following:

enter image description here

[error]COPY failed: stat /var/lib/docker/tmp/docker-builder947419078/KubeApp/KubeApp.csproj: no such file or directory

[error]The process '/usr/bin/docker' failed with exit code 1

Please advise

-- Ken Netherland
azure-devops
azure-pipelines
containers
kubernetes
visual-studio-2019

1 Answer

1/9/2020

[error]COPY failed: stat /var/lib/docker/tmp/docker-builder947419078/KubeApp/KubeApp.csproj: no such file or directory

The cause of this error is actually due to the different execution mechanisms between pipeline and local when running the dockerfile.

For pipeline, it is by default running the docker in the directory where the dockerfile lives which is at the project level, but VS/local runs it at the Repos/Solution level.

So, to solve this issue, you can try with below method

Change the COPY definition as:

    COPY ["KubeApp.csproj", "KubeApp/"]

This method can let you succeed to COPY, but failed with Program does not contain a static 'Main' method.

At this time:

  • One way is change the COPY . .(L10) to COPY . KubeApp/. This will add folder to dest path.
  • Or, you can change the order of COPY(L10) and WORKDIR(L11) without change the COPY . ..

See my previous answer that others solved the same issue by applying my suggestion.

-- Merlin Liang - MSFT
Source: StackOverflow