This project provides a Dockerfile and a Docker Compose setup for running a Python 3.11 application in a containerized environment. The setup uses a multi-stage build for efficient image size and security, and installs dependencies from requirements.txt into a virtual environment.
- Python Version: 3.11 (as specified by the
python:3.11-slimbase image) - Dependencies: All Python dependencies must be listed in
requirements.txt(if present). These are installed into a virtual environment at/app/.venv. - Entrypoint: The default command runs
python main.py. Update theCMDin the Dockerfile if your main entrypoint differs.
- No required environment variables are set by default. If your application needs environment variables, add them to a
.envfile and uncomment theenv_fileline indocker-compose.yml.
-
Build and start the application:
docker compose up --build
This will build the image and start the
python-appservice. -
Customizing the Entrypoint: If your application entrypoint is not
main.py, update theCMDin the Dockerfile or override the command indocker-compose.yml.
- The container runs as a non-root user (
appuser) for improved security. - If your application requires external services (e.g., Postgres, Redis), uncomment and configure the relevant blocks in
docker-compose.yml. - If you need to expose ports (e.g., for a web server), uncomment and adjust the
portssection indocker-compose.yml.
- No ports are exposed by default.
- If your application listens on a port (e.g., 8000 or 5000), uncomment and set the appropriate
portsmapping indocker-compose.yml.
- If your application listens on a port (e.g., 8000 or 5000), uncomment and set the appropriate
Keep this section up to date if you change the Docker setup or add new services.