title: testdriven.io: Test-Driven Development with FastAPI and Docker: Error: Exec format error
body: <p>I'm going through the course Test-Driven Development with FastAPI and Docker from testdriven.io. I am in Part 2 - Deployment.</p>
  <p>When I build the docker container, I can run it locally on my machine. However, when I deploy it to Heroku, it crashes when it starts.</p>
  <p>Here are the Heroku logs:</p>
  <pre><code>2022-08-22T17:59:15.529434+00:00 app[api]: Release v8 created by user xxxx@gmail.com
  2022-08-22T17:59:15.529434+00:00 app[api]: Deployed web (77071f1ecb57) by user xxxx@gmail.com
  2022-08-22T17:59:15.997402+00:00 heroku[web.1]: State changed from crashed to starting
  2022-08-22T17:59:25.752365+00:00 heroku[web.1]: Starting process with command 
  `/bin/sh -c gunicorn\ --bind\ 0.0.0.0:\57978\ app.main:app\ -k\ uvicorn.workers.UvicornWorker`
  2022-08-22T17:59:26.831935+00:00 app[web.1]: Error: Exec format error
  2022-08-22T17:59:26.985717+00:00 heroku[web.1]: Process exited with status 126
  2022-08-22T17:59:27.082554+00:00 heroku[web.1]: State changed from starting to crashed
  2022-08-22T17:59:27.086528+00:00 heroku[web.1]: State changed from crashed to starting
  2022-08-22T17:59:38.283248+00:00 heroku[web.1]: Starting process with command 
  `/bin/sh -c gunicorn\ --bind\ 0.0.0.0:\15987\ app.main:app\ -k\ uvicorn.workers.UvicornWorker`
  2022-08-22T17:59:39.693305+00:00 app[web.1]: Error: Exec format error
  2022-08-22T17:59:39.862628+00:00 heroku[web.1]: Process exited with status 126
  2022-08-22T17:59:40.007558+00:00 heroku[web.1]: State changed from starting to crashed
  </code></pre>
  <p>I cannot find any documentation on the error message or on <code>status 126</code>.</p>
  <p>Here is my Dockerfile.prod:</p>
  <pre><code># pull official base image
  FROM python:3.10.1-slim-buster
  
  # create directory for the app user
  RUN mkdir -p /home/app
  
  # create the app user
  RUN addgroup --system app &amp;&amp; adduser --system --group app
  
  # create the appropriate directories
  ENV HOME=/home/app
  ENV APP_HOME=/home/app/web
  RUN mkdir $APP_HOME
  WORKDIR $APP_HOME
  
  # set environment variables
  ENV PYTHONDONTWRITEBYTECODE 1
  ENV PYTHONUNBUFFERED 1
  ENV ENVIRONMENT prod
  ENV TESTING 0
  
  # install system dependencies
  RUN apt-get update \
      &amp;&amp; apt-get -y install netcat gcc postgresql \
      &amp;&amp; apt-get clean
  
  # install python dependancies
  RUN pip install --upgrade pip
  COPY ./requirements.txt .
  RUN pip install -r requirements.txt
  RUN pip install &quot;uvicorn[standard]==0.16.0&quot;
  
  # copy app
  COPY . .
  
  # chown all the files to the app user
  RUN chown -R app:app $APP_HOME
  
  # change to teh app user
  USER app
  
  # run gunicorn
  CMD gunicorn --bind 0.0.0.0:$PORT app.main:app -k uvicorn.workers.UvicornWorker
  </code></pre>
  <p>Heroku seems to complain about the last line, but I cannot figure out the issue. I will really appreciate some help.</p>