Home > Enterprise >  Deploying Docker Image to Heroku
Deploying Docker Image to Heroku

Time:06-08

I keep running into this error when I try and deploy a docker image (Python 3.10 and MongoDB) using the following commands:

heroku container:login
heroku create ttcv1
heroku container:push web -a ttcv1
heroku container:release web -a ttcv1

Image gets "pushed" but I get an Application error page:

enter image description here

Log below:

`2022-06-07T17:26:12.468116 00:00 heroku[web.1]: Starting process with command `python3`
2022-06-07T17:26:13.339555 00:00 heroku[web.1]: Process exited with status 0
2022-06-07T17:26:13.396838 00:00 heroku[web.1]: State changed from starting to crashed
2022-06-07T17:26:13.405363 00:00 heroku[web.1]: State changed from crashed to starting
2022-06-07T17:26:29.712735 00:00 heroku[web.1]: Starting process with command `python3`
2022-06-07T17:26:31.750611 00:00 heroku[web.1]: Process exited with status 0
2022-06-07T17:26:31.857509 00:00 heroku[web.1]: State changed from starting to crashed
2022-06-07T17:26:33.315159 00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ttcv1.herokuapp.com request_id=bb032403-08cb-42dc-a8a5-8f683601a45a fwd="49.37.171.163" dyno= connect= service= status=503 bytes= protocol=https
2022-06-07T17:26:33.761854 00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ttcv1.herokuapp.com request_id=b7217391-0c68-4315-9c73-c3e687dbbe01 fwd="49.37.171.163" dyno= connect= service= status=503 bytes= protocol=https`

Flask app run:

if __name__ == '__main__':
    app.secret_key = 'mysecret'
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

Here's my docker-compose file

    app:
  build: .
  command: python -u app.py
  
  volumes:
    - .:/app
  links:
    - db
db:
  image: mongo:latest
  hostname: dstudio
  environment:
    - MONGO_INITDB_DATABASE=dstudio
  ports:
    - 27017:27017

My docker file (one of the threads asked changing it to docker.web; tried that too)

FROM python:3.7
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt

Finally, the Procfile (if it matters)

web: gunicorn --bind 0.0.0.0:${PORT} wsgi

CodePudding user response:

In this instance I would recommend setting up an alternative file to handle your deployment different from the Docker Compose file you're using for local dev. Taking a look at the heroku docs you can see they recommend setting up a heroku.yml that would manage building your flask server for you.

That file would look something like this:

build:
  docker:
    app: Dockerfile

To manage your mongo instance you could either use a heroku add on, although all of the mongo instances look like they cost money. I'd suggest setting up a mongodb atlas cluster and then configure your heroku ENV vars to tell the flask server to hit the mongodb cluster. That way it would be free until you started going over their rate limits.

If you're looking for more control over deployment where you can manage everything with a single docker compose file, heroku might not be the best fit for you and I'd encourage you to look at an alternative service.

  • Related