AWS Lightsail tutorial not working

0

I am following this exact example, and copy pasted the exact same steps / code: https://aws.amazon.com/tutorials/serve-a-flask-app/

However my container fails to deploy with the following error: Failed-Deployment

app.py:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
   return "Hello, World!"

if __name__ == "__main__":
   app.run(host='0.0.0.0', port=5000)

requirements.txt:

flask===3.0.0

Dockerfile:

# Set base image (host OS)
FROM python:3.12-alpine

# By default, listen on port 5000
EXPOSE 5000/tcp

# Set the working directory in the container
WORKDIR /app

# Copy the dependencies file to the working directory
COPY requirements.txt .

# Install any dependencies
RUN pip install -r requirements.txt

# Copy the content of the local src directory to the working directory
COPY app.py .

# Specify the command to run on container start
CMD [ "python", "./app.py" ]

containers.json:

{
  "flask": {
      "image": ":flask-service.flask-container.5",
      "ports": {
          "5000": "HTTP"
      }
  }
}

public-endpoint.json:

{
  "containerName": "flask",
  "containerPort": 5000
}
  • Are you creating the files on a Windows computer? If your text editor is incorrectly configured, you might be inserting \r\n or saving in a file format other than UTF-8.

Josh
gefragt vor einem Monat233 Aufrufe
1 Antwort
1

Try to remove the extra = sign in your requirement.txt: flask==3.0.0 and try again.

profile picture
EXPERTE
beantwortet vor einem Monat
  • I am still receiving the exact same error:

    [8/Apr/2024:11:26:38] [deployment:2] Creating your deployment
    [8/Apr/2024:11:26:54] exec /usr/local/bin/python: exec format error
    [8/Apr/2024:11:28:03] [deployment:2] Started 1 new node
    [8/Apr/2024:11:28:12] exec /usr/local/bin/python: exec format error
    [8/Apr/2024:11:29:03] [deployment:2] Started 1 new node
    [8/Apr/2024:11:29:09] exec /usr/local/bin/python: exec format error
    [8/Apr/2024:11:30:16] [deployment:2] Started 1 new node
    [8/Apr/2024:11:30:21] exec /usr/local/bin/python: exec format error
    [8/Apr/2024:11:30:33] [deployment:2] Canceled
    

    In this rerun, I repushed the image, and changed my containers.json to .6 accordingly:

    {
      "flask": {
          "image": ":flask-service.flask-container.6",
          "ports": {
              "5000": "HTTP"
          }
      }
    }
    
  • This error is commonly associated with trying to run a binary compiled for a different architecture, such as running an ARM binary on an x86 system or vice versa. Since you are using a standard Python image from Docker Hub (python:3.12-alpine), it should be compatible with most x86_64 Linux systems. If your Lightsail instance is using a different architecture, that could be the source of the problem.

  • Try to verify that the Docker image architecture matches the Lightsail instance architecture.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen