Docker Deployment
Relevant source files
The following files were used as context for generating this wiki page:
Docker is the recommended deployment method for the Smart Absen Face Recognition system. It encapsulates the application, its dependencies, and configurations into a standardized, portable container. This ensures a consistent environment from development to production, simplifying setup and reducing potential conflicts with the host system's software.
The deployment process involves building a Docker image from a Dockerfile and running it as a container, with application secrets and configurations passed via an environment file. This approach aligns with modern security and infrastructure best practices mentioned in the project documentation.
Sources: README.md:128-130, SECURITY.md:8-17
Prerequisites
Before deploying with Docker, ensure the following are prepared on the host machine:
- Docker Engine: Must be installed and running.
.envFile: A configuration file named.envmust exist in the project's root directory. This file contains essential secrets and settings, such as database credentials and the application'sSECRET_KEY. The project provides an.env.exampletemplate to create this file.
Sources: README.md:31-32, SECURITY.md:10-17
Building the Docker Image
The Docker image encapsulates the entire application stack, including the Flask backend, Python dependencies, and static assets. The build process is orchestrated by a Dockerfile located in the project root.
The README.md provides the command to build the image:
docker build -t smart-absen .
This command reads the Dockerfile, installs all dependencies listed in requirements.txt, copies the application source code (like app.py, models.py, etc.) into the image, and tags the resulting image as smart-absen.
Sources: README.md:129, CLEANUP_REPORT.md:43-61
Build Process Flow
The diagram below illustrates the steps Docker takes during the image build process.
This flow is inferred from the project structure and standard Docker practices for Python applications.
Sources: README.md:129, CONTRIBUTING.md:65-83, INSTALLATION.md:112-123
Running the Docker Container
Once the image is built, it can be run as a container. The application inside the container is configured using the .env file from the host, which is securely passed during startup.
The command to run the container is:
docker run -p 5001:5001 --env-file .env smart-absen
This command performs the following actions:
docker run: Creates and starts a new container from thesmart-absenimage.-p 5001:5001: Maps port 5001 on the host to port 5001 inside the container, making the application accessible athttp://localhost:5001.--env-file .env: Injects all variables from the.envfile into the container's environment. This is the recommended method for handling secrets.
Sources: README.md:130, SECURITY.md:8-17
Container Run Flow
This diagram shows how the docker run command initiates and configures the application container.
Environment Configuration
The application's behavior is controlled by environment variables. The Docker deployment strategy relies on an .env file to manage these settings without hardcoding them into the image.
The following table summarizes the key environment variables required for the Docker container to run correctly.
| Variable | Description | Example Value |
|---|---|---|
DB_HOST | The hostname or IP address of the MySQL database. | localhost or a DB service name |
DB_USER | The username for the MySQL database. | root or smartabsen |
DB_PASSWORD | The password for the MySQL database user. | yourpassword |
DB_NAME | The name of the database to use. | smart_absen |
SECRET_KEY | A long, random string used for session security. | your-secret-key |
FLASK_ENV | The Flask environment mode. | production |
PORT | The port the Flask application will listen on inside the container. | 5001 |
FACE_CONFIDENCE | The confidence threshold for face recognition. | 0.6 |
MAX_FACES | The maximum number of faces to detect in a single frame. | 1 |
Sources: README.md:118-126, SECURITY.md:43-46, INSTALLATION.md:195-206
Deployment Architecture Overview
The following diagram illustrates the components involved in a Docker-based deployment on a single host.
This diagram shows the user accessing the application via the mapped port on the host. The Docker Engine manages the container, which runs the Flask application. The .env file on the host securely provides configuration to the application running inside the isolated container environment.
Sources: README.md:128-130, SECURITY.md:8-17
Summary
Deploying the Smart Absen system with Docker is the recommended approach, offering significant benefits in terms of consistency, security, and ease of setup. By packaging the application into a self-contained image and managing configuration externally via an .env file, the deployment process becomes reliable and portable across different environments. The provided commands in the README.md serve as the primary entry point for building and running the application.
Sources: README.md:128-130