Reputation: 1043
I am trying to setup a docker compose deployment but I have having an issue with the COPY that is in one of the projects. I have tried changing the path a few times without any luck. I continue to get the following issue:
ERROR: Service 'cryptoappapi' failed to build : COPY failed: file not found in
build context or excluded by .dockerignore: stat
CryptoApp.Api/CryptoApp.Api.csproj: file does not exist
This is my layout
This is my docker file is standard:
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 ["CryptoApp.Api/CryptoApp.Api.csproj", "CryptoApp.Api/"]
RUN dotnet restore "CryptoApp.Api/CryptoApp.Api.csproj"
COPY . .
WORKDIR "/src/CryptoApp.Api"
RUN dotnet build "CryptoApp.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "CryptoApp.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CryptoApp.Api.dll"]
This is my docker compose:
services:
# First the AspNet Core app
cryptoappapi:
## Get the image to use and set the container name
image: cryptoappapi:latest
container_name: cryptoappapi
# State a dependancy on Redis working
depends_on:
- "redis_image"
- "postgres_image"
# Location of the Dockerfile
build:
context: ./CryptoApp.Api
dockerfile: Dockerfile
# Set access ports for localhost on the left
ports:
- "80:5000"
- "443:5001"
# Configure a link to Redis
links:
- "redis_image"
- "postgres_image"
# The Application needs a connection string for Redis, this just needs to be the Redis Service name as defined below
# Pass it in as an Environmental Variable
environment:
- RedisConnection=redis_image
- DB_CONNECTION_STRING="host=postgres_image;port=5432;database=xx;username=xxx;password=xxx"
# Set them all to the same network
networks:
- dockerapi-dev
Upvotes: 2
Views: 5669
Reputation: 1403
In docker compose file, build
can be specified either as a string containing a path to the build context or as an object with the path specified under context
and optionally Dockerfile
.
If you set context, this context is sent to the Docker daemon and compose built image from directory that you specified.
Also you don't need to include that directory name when COPY csproj to docker If you dont want to change you docker file, you can edit your docker compose file and change your context to current directory and set full docker file directory.
services:
# First the AspNet Core app
cryptoappapi:
## Get the image to use and set the container name
image: cryptoappapi:latest
container_name: cryptoappapi
# State a dependancy on Redis working
depends_on:
- "redis_image"
- "postgres_image"
# Location of the Dockerfile
build:
context: .
dockerfile: /CryptoApp.Api/Dockerfile
...
And also you can just change your docker file by this way if you dont want to change docker compose:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["CryptoApp.Api.csproj", "CryptoApp.Api/"]
RUN dotnet restore "CryptoApp.Api/CryptoApp.Api.csproj"
Upvotes: 1