如何在运行Docker文件时使用卷检索发布输出

lmyy7pcs  于 2022-12-18  发布在  Docker
关注(0)|答案(1)|浏览(122)

我无法从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

有人帮忙吗?

clj7thdc

clj7thdc1#

您将容器中的挂载点设置为/src/app,但由于WORKDIR /app,app目录实际上位于根目录下。

docker run --rm -v ${MOUNT_POINT}:/app xxx/helloapi:$CI_PIPELINE_IID

相关问题