405 不允许将 Docker 容器部署到 heroku 的方法

问题描述 投票:0回答:1

所以我有一个使用 langchain 的 Flask 应用程序,我一直在尝试将其部署在 Heroku 上。问题是,docker 镜像在没有 Heroku 部署的情况下构建和运行得非常好,我只在部署到 Heroku 时遇到问题。我按照以下说明进行操作:

  1. 登录heroku:
    heroku login
  2. 登录heroku容器:
    heroku container:login
  3. 使用dockerfile进入flask目录并运行:
    heroku container:push web --app <app-name>

当我运行步骤 3 时,我不断收到此错误:

[+] Building 2.1s (12/12) FINISHED                                docker:desktop-linux
 => [internal] load build definition from Dockerfile                              0.0s
 => => transferring dockerfile: 226B                                              0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1         0.8s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:865e5dd094beca432  0.0s
 => => resolve docker.io/docker/dockerfile:1@sha256:865e5dd094beca432e8c0a1d5e1c  0.0s
 => [internal] load metadata for docker.io/library/python:3.12-slim               0.8s
 => [internal] load .dockerignore                                                 0.0s
 => => transferring context: 2B                                                   0.0s
 => [1/5] FROM docker.io/library/python:3.12-slim@sha256:af4e85f1cac90dd3771e472  0.0s
 => => resolve docker.io/library/python:3.12-slim@sha256:af4e85f1cac90dd3771e472  0.0s
 => [internal] load build context                                                 0.0s
 => => transferring context: 93B                                                  0.0s
 => CACHED [2/5] WORKDIR /test                                                    0.0s
 => CACHED [3/5] COPY requirements.txt requirements.txt                           0.0s
 => CACHED [4/5] RUN pip install -r requirements.txt                              0.0s
 => CACHED [5/5] COPY . .                                                         0.0s
 => exporting to image                                                            0.1s
 => => exporting layers                                                           0.0s
 => => exporting manifest sha256:8e61290c43414b6925441272dc06f4f0a4f23b5c5de7755  0.0s
 => => exporting config sha256:0931ca17cf70351a4cef92bbdfac6230b22c455c17544e2ac  0.0s
 => => exporting attestation manifest sha256:44105731c3395578fbc710ba7d7828abd44  0.0s
 => => exporting manifest list sha256:5bd92a0f9fc31324aab464d82285036b61a2132a53  0.0s
 => => naming to registry.heroku.com/indic-power/web:latest                       0.0s
 => => unpacking to registry.heroku.com/indic-power/web:latest                    0.0s
=== Pushing web (C:\Users\Photogauge\Desktop\rahul\docker\test\Dockerfile)

Using default tag: latest
The push refers to repository [registry.heroku.com/indic-power/web]
b91db956ff46: Pushed
6b08635bc459: Layer already exists
23acc3c7fc2a: Pushed
c8daa4e2ec2f: Pushed
8341816e3d13: Layer already exists
302e3ee49805: Layer already exists
38732fc0313c: Pushed
0bc61d7a3c35: Pushed
18bb7c8edce2: Layer already exists
failed commit on ref "manifest-sha256:8e61290c43414b6925441272dc06f4f0a4f23b5c5de775529a798ccda90ce0d2": unexpected status from PUT request to https://registry.heroku.com/v2/indic-power/web/manifests/latest: 405 Method Not Allowed
 »   Error: docker push exited with Error: 1

这是我的dockerfile:

#syntax=docker/dockerfile:1
FROM python:3.12-slim

WORKDIR /power

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY data/ data/

COPY . .

CMD [ "python", "api.py"]

和我的 docker-compose.yaml:

version: '2'
services:
  web:
    build: .
    ports: 
      - "5000:5000"
    volumes:
      - .:/app
    working_dir: /app
    command: python api.py
    env_file:
      - .env

我尝试使用

清除docker缓存
docker builder prune
docker system prune -a

但这没有什么区别。我做错了什么?

docker flask heroku
1个回答
0
投票

问题是 BuildKit 0.11 默认启用“provenance”,请参阅:https://help.heroku.com/74S3XXMP/workaround-for-docker-push-error-405-method-not-allowed-using-buildkit- 0-11

解决方案取决于您将图像形式推送到的位置。例如,使用 Github 操作

build-push-action
,您可以执行以下操作:

- name: Docker build
  uses: docker/build-push-action@v3
  with:
    provenance: false
© www.soinside.com 2019 - 2024. All rights reserved.