我无法从container. Docker文件中检索/app/publish内容,锁定如下
...
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /src
COPY ["HellodAPI/HelloAPI.csproj", "HelloAPI/"]
RUN dotnet restore "HellodAPI/HellodAPI.csproj"
COPY . .
WORKDIR "/src/HelloAPI"
RUN dotnet build "HelloAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "HelloAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HelloAPI.dll"]
我使用的是Gitlab Ci,代码如下所示:
Build job:
stage: build
image:
name: amazon/aws-cli
entrypoint: [""]
variables:
MOUNT_POINT: /builds/$CI_PROJECT_PATH/app/build
before_script:
- amazon-linux-extras install docker
- aws --version
- docker --version
- yum install -y tar
services:
- docker:dind
script:
- mkdir -p ${MOUNT_POINT}
- docker build --target publish -f HelloAPI/Dockerfile -t xxx/helloapi:$CI_PIPELINE_IID .
- docker run --rm -v ${MOUNT_POINT}:/src/app xxx/helloapi:$CI_PIPELINE_IID
- tar -czvf publish.tar.gz ${MOUNT_POINT}/*
- cp publish.tar.gz ${CI_PROJECT_DIR}
artifacts:
when: on_success
paths:
- ./publish.tar.gz
我可以发布并运行,但tar命令返回此错误:
tar: /builds/xxxx/xxxx/app/publish/*: Cannot stat: No such file or directory
有人帮忙吗?
1条答案
按热度按时间clj7thdc1#
您将容器中的挂载点设置为
/src/app
,但由于WORKDIR /app
,app目录实际上位于根目录下。