Python
Step 1: Create a Python Application
from flask import Flask
app = Flask(__name__)
@app.route('/health')
def health_check():
return "OK", 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)Step 2: Create a Dockerfile
# Use official Python image
FROM python:3.9
# Set the working directory
WORKDIR /app
# Copy application files
COPY app.py requirements.txt /app/
# Install dependencies
RUN pip install -r requirements.txt
# Expose port
EXPOSE 5000
# Command to run the application
CMD ["python", "app.py"]You can build image and use i another vm
Step 3: Add Health Check in docker-compose.yml
Step 4: Build and Run Containers
Step 5: Check Health Status
Step 6: Simulate a Failing Health Check
Last updated