如何解决如何在Dockerfile阶段之间使用全局安装的工具?
我有一个Dockerfile,我试图在其中使用多个阶段来生成单个映像,我可以将其重新用于运行数据库迁移和API本身。
运行API效果很好,但是当我从迁移阶段执行db-migration时,出现一条错误消息,提示命令不可用。看来dotnet-ef命令在此阶段不可用。
我不太确定如何确保在该阶段可以使用它?
文件如下:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build
COPY . ./src
WORKDIR /src
RUN dotnet publish -c Release -o /app
FROM build AS tests
WORKDIR /src/Infrastructure.Api.Tests
FROM build AS migrations
RUN dotnet tool install --global dotnet-ef
ENV PATH ${PATH}:/root/.dotnet/tools
WORKDIR /src/Infrastructure.Persistence
FROM base AS publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
然后我使用docker compose文件在迁移阶段执行数据库更新:
version: "3.8"
services:
db-migrations:
build:
context: .
dockerfile: Dockerfile
target: migrations
env_file: .env
entrypoint:
- dotnet
- ef
- database
- update
depends_on:
- db
错误如下:
db-migrations_1 | Could not execute because the specified command or file was not found.
db-migrations_1 | Possible reasons for this include:
db-migrations_1 | * You misspelled a built-in dotnet command.
db-migrations_1 | * You intended to execute a .NET Core program,but dotnet-ef does not exist.
db-migrations_1 | * You intended to run a global tool,but a dotnet-prefixed executable with this name could not be found on the PATH.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。