I am having trouble getting a hello world Flask app up and running on lightsail. I am following this tutorial.
I am at the end of Step 4 where I deploy the container. My service-name
is flask-service2
, and after running
aws lightsail create-container-service-deployment --service-name flask-service2 --containers file://containers.json --public-endpoint file://public-endpoint.json
then
aws lightsail get-container-services --service-name flask-service2
,
the console displays
"containerServiceName": "flask-service2",
...
"state": "READY",
...
"url": "https://flask-service2.********.us-east-1.cs.amazonlightsail.com/",
When I navigate to this url, though, I receive a browser 404 No Such Service
.
In the lightsail console, I go to Containers > flask-service2 > Deployments then there is a date with my deployment, and it says Status
Failed
. I click the three dots, Show details
, Open log
and the only thing that shows is
[8/Feb/2024:10:17:08] [deployment:3] Creating your deployment
[8/Feb/2024:10:18:11] [deployment:3] Started 1 new node
[8/Feb/2024:10:19:13] [deployment:3] Started 1 new node
[8/Feb/2024:10:20:07] [deployment:3] Started 1 new node
[8/Feb/2024:10:20:26] [deployment:3] Canceled
I have Example: [DEBUG]
, and it still shows this after Refresh
. I am ultimately trying to view the detailed logs of the container deployment, so I can understand why the container deployment has failed.
I have read this page, but I am not sure what to stdout
to view all errors, and I have read this page, but the instructions seem to match what I am already doing.
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)
containers.json
{
"flask": {
"image": "flask-service2.flask-container2.3",
"ports": {
"5000": "HTTP"
}
}
}
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" ]
public-endpoints.json
{
"containerName": "flask",
"containerPort": 5000
}
requirements.txt
flask==3.0.0
I also have .env
and .gitignore
but am not using them.
This has solved the problem. I inserted the colon, so "image": ": flask-service2.flask-container2.3", and now it works! Thank you Ramneek.