Stefan Voicila
Stefan Voicila

Reputation: 63

docker-compose build copy failed

I'm trying to upload my project to a Digital Ocean droplet using docker i'm stuck in this stage, where COPY fails whenever i run docker-compose build.

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["iCoose.API/iChoose.API.csproj", "iCoose.API/"]
COPY ["iChoose.Business.Entities/iChoose.Business.Entities.csproj", "iChoose.Business.Entities/"]
COPY ["iChoose.Business.Services/iChoose.Business.Services.csproj", "iChoose.Business.Services/"]
COPY ["iChoose.Common.Core/iChoose.Common.Core.csproj", "iChoose.Common.Core/"]
COPY ["iChoose.DataAccess.Data/iChoose.DataAccess.Data.csproj", "iChoose.DataAccess.Data/"]
RUN dotnet restore "iCoose.API/iChoose.API.csproj"
COPY . .
WORKDIR "/src/iCoose.API"
RUN dotnet build "iChoose.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "iChoose.API.csproj" -c Release -o /app/publish

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

docker-compose.yml:

#docker-compose

version: '2'

services:
  app:
    build:
      context:  ./
      dockerfile: Dockerfile
  https-portal:
    image: steveltn/https-portal:1
    ports:
      - '80:80'
      - '443:443'
    links:
      - app
    restart: always
    environment:
      DOMAINS: 'domain.com -> http://app:5000'
      STAGE: 'production'

When I run the 'docker-compose build' command in the servers terminal it starts building until it gets to the first COPY command, where I get:

ERROR: Service 'app' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder987069796/iCoose.API/iChoose.API.csproj: no such file or directory.

I checked the files and there is no directory in that path after the 'tmp' folder, which is empty.

Upvotes: 1

Views: 3956

Answers (1)

Ziaullah Khan
Ziaullah Khan

Reputation: 2246

The Dockerfile and docker-compose.yaml files should be right next to sln and csproj file.

When you create a new project in Visual Studio and leave put project file inside the project folder this issue might occure. Make sure you have sln and csproj in the same folder. Also, the Dockerfile and 'docker-compose.yaml` in the same folder too.

Deeper answer:

Dockerfile contains instructions for the docker engine on how to create a docker image for your application. Each line is a layer of docker image.

FROM

COPY

RUN

CMD

All these commands will create a new docker image, which are cache by the engine for next run.

Because these images are Linux based and linux uses cgroup and namespaces to create isolated environment which is the feature on which docker is built. This isolated environment has a special folder which is appearing in the error message.

Upvotes: 2

Related Questions