Simple Dockerfile to test AWS ECR and ECS

For a specific task (run and exit), Dockerfile could be:

FROM ubuntu
CMD ["echo", "Hello, World!"]

Build this Dockerfile:

docker build -t helloworld:1.0.0 .

Tag the image:

docker tag helloworld:1.0.0 <aws_account_id>.dkr.ecr.<region>.amazonaws.com/helloworld:1.0.0

Upload the image to ECR:

docker push <aws_account_id>.dkr.ecr.<region>.amazonaws.com/helloworld:1.0.0

In ECS, create “Cluster”, then create “Task Definition”, finally “Run new task”.

For a continuous service (like Web server), Dockerfile could be:

# 1. Use the official lightweight base image that comes with Python
FROM python:3.11-slim

# 2. Set the working directory
WORKDIR /app

# 3. Create a simple HTML webpage to satisfy the AWS health checks
RUN echo "Hello, World! I am alive!" > index.html

# 4. Explicitly inform Docker that our container will use port 80 (this aligns with Express Mode default settings)
EXPOSE 80

# 5. Start Python's built-in HTTP server. 
# It perfectly responds to all requests sent by the ALB (Application Load Balancer) and will never exit on its own!
CMD ["python", "-m", "http.server", "80"]

Build this Dockerfile:

docker build -t helloworld:2.0.0 .

Tag the image:

docker tag helloworld:2.0.0 <aws_account_id>.dkr.ecr.<region>.amazonaws.com/helloworld:2.0.0

Upload the image to ECR:

docker push <aws_account_id>.dkr.ecr.<region>.amazonaws.com/helloworld:2.0.0

In ECS, choose “Express Mode”.