From local Python app to cloud-hosted container
/3030from flask import Flask, render_template
import os
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
if __name__ == "__main__":
port = int(
os.environ.get('PORT', 3030)
)
app.run(
debug=True,
host='0.0.0.0',
port=port
)
On an Apple Silicon Mac (M1/M2/M3), your machine runs arm64. AWS runs linux/amd64. If you don't specify the platform at build time, the image silently fails on AWS.
# Wrong — builds for arm64 (your Mac)
docker build -t contain-my-flask .
# Correct — builds for linux/amd64 (AWS)
docker buildx build \
--platform linux/amd64 \
-t contain-my-flask:1.0.0 .
FROM python:3.8-alpine
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "/app/main.py"]
eu-west-2.
# Authenticate
aws ecr get-login-password \
--region eu-west-2 \
| docker login \
--username AWS \
--password-stdin \
<acct>.dkr.ecr.eu-west-2.amazonaws.com
# Tag
docker tag contain-my-flask:latest \
<acct>.dkr.ecr.eu-west-2.amazonaws.com\
/contain-my-flask:latest
# Push
docker push \
<acct>.dkr.ecr.eu-west-2.amazonaws.com\
/contain-my-flask:latest
eu-west-2. Mixing regions means Fargate cannot pull the image.
Containers solve real problems. Packaging the app and its environment together eliminates "works on my machine". The image runs identically everywhere.
ECR, ECS, and Fargate form a pipeline. Each AWS service has one job: store the image, orchestrate the task, provide the compute. They compose cleanly.
Region consistency is non-negotiable. All AWS services must be in the same region. One mismatch breaks the whole deployment.
Fargate removes the undifferentiated heavy lifting. No EC2 instances, no patching, no capacity planning. Define the task and run it.