Docker Compose在复制时失败
我正在尝试设置docker compose部署,但其中一个项目中的副本存在问题。我尝试过几次改变路线,但都没有任何运气。我继续得到以下问题:Docker Compose在复制时失败,docker,asp.net-core,docker-compose,Docker,Asp.net Core,Docker Compose,我正在尝试设置docker compose部署,但其中一个项目中的副本存在问题。我尝试过几次改变路线,但都没有任何运气。我继续得到以下问题: 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
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
这是我的布局
这是我的docker文件是标准的:
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"]
这是我的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
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"
在docker compose文件中,
build
可以指定为包含生成上下文路径的字符串,也可以指定为具有在context
下指定的路径的对象,还可以选择Dockerfile
如果设置了上下文,则该上下文将发送到Docker守护进程,并从指定的目录合成生成的映像
另外,将csproj复制到docker时,不需要包含该目录名
如果不想更改docker文件,可以编辑docker compose文件,将上下文更改为当前目录,并设置完整的docker文件目录
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
...
如果您不想更改docker compose,也可以通过这种方式更改docker文件:
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
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"
您可以在物理级别共享文件夹结构吗?如果您的
构建:{context:}
是CryptoApp.Api
目录,则在复制
时不需要同时包含该目录名;只需将./CryptoApp.Api.csproj
复制到映像树中。@DavidMaze因此,如果我删除,我会得到下一个错误服务“cryptoapppi”无法生成:命令“/bin/sh-c dotnet build”CryptoApp.Api.csproj”-c Release-o/app/build'返回非零代码:1此CSC:error CS5001:程序不包含适合入口点的静态“Main”方法[/src/CryptoApp.Api/CryptoApp.Api.csproj]已添加副本。在跑步之前,现在很开心