An API that retrieves current and forecast weather data.
8.3K
This is the official image for the Weather API application, a robust REST API built with Python (Flask). The image is optimized using python:3.13-alpine, ensuring high performance, reduced size, and a secure environment for production workloads.
The image packages all the application code and dependencies, making it ready to run in any containerized environment. It is configured following Docker best practices:
entrypoint.sh script to automatically run database migrations (flask db upgrade) before starting the server.gunicorn (WSGI server) optimized with 2 workers, request limiters (max-requests, max-requests-jitter), and timeouts for maximum stability.5000.fuser), providing an essential layer of security.http://localhost:5000You can also test the endpoints, read the API documentation, and see this exact API running in production at: https://weatherapi.lat
The application requires a PostgreSQL database to function. The easiest way to start is by running the API alongside the database container, without requiring Redis.
Create a docker-compose.yml with the following content:
services:
db:
image: postgres:17
environment:
POSTGRES_DB: weather_db
POSTGRES_USER: postgres_user
POSTGRES_PASSWORD: your_secure_password
volumes:
- db_weather_data:/var/lib/postgresql/data
networks:
- weather_network
web:
image: rafaelrodriguess/weather-api:latest
ports:
- "5000:5000"
depends_on:
- db
environment:
- SECRET_KEY="your-super-secure-secret-key"
- JWT_SECRET_KEY="your-jwt-secret-key"
- DATABASE_URL=postgresql://postgres_user:your_secure_password@db:5432/weather_db
networks:
- weather_network
volumes:
db_weather_data:
networks:
weather_network:
.env)You can configure the application's behavior using a .env file. Place it in the same directory as your docker-compose.yml:
# Application Settings
SECRET_KEY="your-super-secure-secret-key"
JWT_SECRET_KEY="your-jwt-secret-key"
# External Services (Mandatory Database)
DATABASE_URL="postgresql://postgres_user:postgres_password@db:5432/weather_db"
# (Optional) Cache Broker - If omitted, app runs without Redis
REDIS_URL="redis://redis:6379/0"
# Postgres container creation variables
POSTGRES_USER=postgres_user
POSTGRES_PASSWORD=postgres_password
POSTGRES_DB=weather_db
For a highly available production environment, it's recommended to run the API alongside dedicated PostgreSQL and Redis containers.
Create a docker-compose.yml with this advanced setup:
services:
db:
image: postgres:17
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- db_weather_data:/var/lib/postgresql/data
networks:
- weather_network
redis:
image: redis:7-alpine
networks:
- weather_network
web:
image: rafaelrodriguess/weather-api:latest
ports:
- "5000:5000"
depends_on:
- db
- redis
env_file:
- ./.env
networks:
- weather_network
volumes:
db_weather_data:
networks:
weather_network:
This image was carefully designed for production usage:
fuser): Ensures the app doesn't have root privileges, limiting potential internal security vulnerabilities.Gunicorn instead of Flask's built-in development server, configured to prevent memory leaks and handle multiple concurrent connections.PYTHONDONTWRITEBYTECODE=1 and PYTHONUNBUFFERED=1 are active to prevent caching clutter and ensure immediate logging output.Developed by Rafael Rodrigues.
Content type
Image
Digest
sha256:5dc3a35e3…
Size
43.6 MB
Last updated
2 months ago
docker pull rafaelrodriguess/weather-api