<p>I am trying to deploy python fastApi in EKS cluster (I am able to test this code in my local system), whenever I am deploying the docker image, its failing with error as</p>
<blockquote>
<p>&quot;</p>
<pre><code>INFO:     Will watch for changes in these directories: ['/app']
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [1] using statreload
ERROR:    Error loading ASGI app. Attribute &quot;app&quot; not found in module &quot;main&quot;.
</code></pre>
<p>&quot;</p>
</blockquote>
<p>I have created the docker image and pushed it to local repository, during deployment I am able to pull the image but not able to create container and when I checked Pod logs I got above error message .
My main.py file content-</p>
<pre><code>from typing import Optional
from fastapi import FastAPI

app = FastAPI()

@app.get(&quot;/&quot;)
def read_root():
    return {&quot;Hello&quot;: &quot;World&quot;}

@app.get(&quot;/items/{item_id}&quot;)
def read_item(item_id: int, q: Optional[str] = None):
    return {&quot;item_id&quot;: item_id, &quot;q&quot;: q}
</code></pre>
<p>My docker file-</p>
<pre><code>FROM python:3.9.5
COPY . /app
COPY .pip /root
WORKDIR /app

RUN pip3 install -r docker_req.txt

#COPY ./main.py /app/
#COPY ./__init__.py /app/

CMD [&quot;uvicorn&quot;, &quot;main:app&quot;, &quot;--reload&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;]
</code></pre>
<p>Deployment file looks like this-</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: &quot;1&quot;
    meta.helm.sh/release-name: cti-datalake-poc
    meta.helm.sh/release-namespace: **********&lt;replaced the name&gt;
  generation: 1
  labels:
    app: cti-datalake-poc
    app.kubernetes.io/instance: cti-datalake-poc
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: cti-datalake-poc
    app.kubernetes.io/version: 1.0.0
    helm.sh/chart: cti-datalake-poc-1.0.0
    version: 1.0.0
  name: cti-datalake-poc
  namespace: **********&lt;replaced the name&gt;
  resourceVersion: &quot;******&quot;

spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: cti-datalake-poc
      app.kubernetes.io/instance: cti-datalake-poc
      app.kubernetes.io/name: cti-datalake-poc
      version: 1.0.0
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: cti-datalake-poc
        app.kubernetes.io/instance: cti-datalake-poc
        app.kubernetes.io/name: cti-datalake-poc
        deployid: *****
        version: 1.0.0
    spec:
      containers:
      - image: develop-ctl-dl-poc/cti-datalake-poc:1.0.5.0
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: http
            scheme: HTTP
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        name: cti-datalake-poc
        ports:
        - containerPort: 5000
          name: http
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: http
            scheme: HTTP
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          limits:
            cpu: 200m
            memory: 256Mi
          requests:
            cpu: 100m
            memory: 128Mi
        securityContext: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: ***&lt;name removed&gt;
      restartPolicy: Always
      schedulerName: default-scheduler

      serviceAccount: default
      serviceAccountName: default
      terminationGracePeriodSeconds: 30
</code></pre>
<p>requirement.txt is</p>
<pre><code>fastapi==0.73.0
pydantic==1.9.0
uvicorn==0.17.0
</code></pre>
<p>Any help is appreciated.</p>

<p>Add the directory name in front of filename i.e; if your directory name is <code>app</code></p>
<p>change <code>main:app</code> to <code>app.main:app</code> so in <code>CMD</code> of Dockerfile this will be</p>
<pre><code>CMD [&quot;uvicorn&quot;, &quot;app.main:app&quot;, &quot;--reload&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;]
</code></pre>
<p>In addition you can check <a href="https://stackoverflow.com/questions/60819376/fastapi-throws-an-error-error-loading-asgi-app-could-not-import-module-api">this</a> SO post.</p>
