405 Method Not Allowed for Docker container deployment to heroku

So I have a flask application using langchain that I’ve been trying to deploy on heroku. The thing is, the docker image builds and runs perfectly fine without the heroku deployment, I only run into issues when deploying to heroku. I followed these instructions:

  1. Login to heroku: heroku login
  2. Login to heroku container: heroku container:login
  3. Go to flask directory with dockerfile and run: heroku container:push web --app <app-name>

When I run step 3, I keep getting this error:

[+] 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

This is my 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"]

and my docker-compose.yaml:

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

I’ve tried clearing the docker cache with

docker builder prune
docker system prune -a

but it makes no difference. What am I doing wrong?

It looks like you’re encountering an issue with pushing your Docker image to Heroku due to the error 405 Method Not Allowed during the push request. This error is typically associated with an HTTP method not being allowed for the specified resource. Here’s a breakdown of potential causes and solutions:

1. Check Heroku Registry and App Name

Ensure that you are correctly logged into the Heroku container registry and that your app name (indic-power in this case) is correctly specified. The command you’re running:

heroku container:push web --app <app-name>

should have the correct app name in the <app-name> part. Double-check this, especially in cases where you may have multiple Heroku apps.

To confirm that your app name is correct and that you’re logged into Heroku, run:

heroku apps

Ensure your app appears in the list and you’re targeting the correct app.

2. Correct Tagging for Heroku Registry

Heroku requires that Docker images are tagged correctly before pushing. It looks like the tag is correctly being set to registry.heroku.com/indic-power/web:latest, but you might want to explicitly tag the image before pushing. Try this:

docker tag <image-id> registry.heroku.com/indic-power/web:latest

You can find the image ID by running docker images to get a list of all images and their respective IDs. After tagging, attempt to push again:

heroku container:push web --app indic-power

3. Heroku Stack Compatibility

Ensure that the stack your Heroku app is using is compatible with your Docker setup. Heroku recently introduced some new stacks, and your app may need to be upgraded. To check and update the stack:

heroku stack:set heroku-22 --app indic-power

Then, try pushing the image again.

4. Rebuild the Image

Sometimes cached layers can cause issues. You’ve already cleared the cache, which is good, but you may want to try rebuilding the image without using cache:

docker build --no-cache -t registry.heroku.com/indic-power/web .

Afterward, attempt the push again:

heroku container:push web --app indic-power

5. Alternative Push Method

If the Heroku CLI push continues to fail, you can try manually pushing the image using Docker commands:

  1. Login to Heroku’s container registry:
docker login --username=_ --password=$(heroku auth:token) registry.heroku.com
  1. Tag the image manually (if not already tagged):
docker tag <image-id> registry.heroku.com/indic-power/web
  1. Push the image to the registry:
docker push registry.heroku.com/indic-power/web
  1. Release the image on Heroku:
heroku container:release web --app indic-power

6. Check API Limits or Heroku Quota

Heroku may block or limit requests based on the account tier you are using (free, hobby, or paid). If your account has reached a quota limit (like Docker container pushes per hour/day), you might run into issues like this. Check your account status on Heroku or try deploying again after some time.

7. Check Heroku Docker Registry Status

Sometimes Heroku’s registry may experience issues. You can check if Heroku is facing any ongoing service disruptions here: Heroku Status.

8. Dockerfile Review

Your Dockerfile looks mostly fine, but you could make a few optimizations:

  • Ensure you’re using the correct working directory (/power in your case).
  • Ensure that the CMD instruction is correct. It seems like you’re running a Flask app. Make sure that api.py is indeed the correct entry point for your application.

Next Steps

After trying the above fixes, retry pushing the Docker image to Heroku. If you’re still facing issues, share any new error messages or logs, and I can further assist!

You have not enough Humanizer words left. Upgrade your Surfer plan.