Chirdeep Tomar
Chirdeep Tomar

Reputation: 4461

VSTS unable to build a docker image

I have a simple out of the box VS2017 web api that I am trying to build a Docker Image for on VSTS and publish the image to Azure container registry. But its not working, error below:

2018-05-21T16:49:45.8481201Z Step 7/17 : COPY WebApi/WebApi.csproj WebApi/
2018-05-21T16:49:45.8503445Z COPY failed: stat /var/lib/docker/tmp/docker-builder936381234/WebApi/WebApi.csproj: no such file or directory
2018-05-21T16:49:45.8644972Z ##[error]COPY failed: stat /var/lib/docker/tmp/docker-builder936381234/WebApi/WebApi.csproj: no such file or directory
2018-05-21T16:49:45.8732546Z ##[error]/usr/local/bin/docker failed with return code: 1

Its a standard VS2017 solution.

Dockerfile

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 63537
EXPOSE 44369

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY WebApi/WebApi.csproj WebApi/
RUN dotnet restore WebApi/WebApi.csproj
COPY . .
WORKDIR /src/WebApi
RUN dotnet build WebApi.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish WebApi.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApi.dll"]

.dockerignore

.dockerignore
.env
.git
.gitignore
.vs
.vscode
docker-compose.yml
docker-compose.*.yml
*/bin
*/obj

docker-compose.yml

version: '3.4'

services:
  webapi:
    image: webapi
    build:
      context: .
      dockerfile: WebApi/Dockerfile

I have tried all the suggested solutions by changing the .dockerignore file, deleting it etc etc.

Upvotes: 3

Views: 3833

Answers (5)

Waleed Al Harthi
Waleed Al Harthi

Reputation: 914

I had the same problem on Visual Studio 2019. This is what solved it for me:

  1. Delete Dockerfile; copy your customizations somewhere if you made any!
  2. Right click the project -> Add -> Docker support, this should generate a new docker file. Copy your custom stuff back in.
  3. Right click the project -> Edit Project File.
  4. Find this line <DockerfileContext>.</DockerfileContext> and remove it.

Upvotes: 3

officer
officer

Reputation: 2458

My problem was that I had an unnecessary Dockerfile that was located in a subdirectory.

Since VSTS by default searches for the Dockerfile with **/Dockerfile, this unnecessary Dockerfile was used, resulting in a wrong context. The correct Dockerfile was ignored.

Upvotes: 0

Chirdeep Tomar
Chirdeep Tomar

Reputation: 4461

I was using the Docker instead of Docker Compose task from the build tasks agents. Change to Docker Compose and point to Docker compose file did the trick.

Upvotes: 0

scourer
scourer

Reputation: 49

Your context in the compose file should be - context: ./WebApi

As mentioned in other answer Docker build takes directory as context which is the root directory of contents it needs to build the image.

Upvotes: 0

starian chen-MSFT
starian chen-MSFT

Reputation: 33728

It is based on the build context to copy files, by default, the Use Default Build Context option is checked for Docker task, you need to uncheck this option and specify the corresponding path (same level of solution), for example . for root folder.

Upvotes: 10

Related Questions