-
Notifications
You must be signed in to change notification settings - Fork 7
Best Practices for Dockerfiles
The recommended structure for a Dockerfile --
- system dependencies
- Python dependencies (requirements.txt)
- schemas
- model files (if any)
- application code
This results in the most efficient caching, and faster rebuilds. System dependencies are the least likely to change, so placing them first allows Docker to cache this layer and avoid redundant installations during rebuilds. Python dependencies, specified in requirements.txt, are next because they change more frequently than system dependencies but less often than the application code. By adding schemas before the application code, we ensure they are cached separately, hence reducing rebuild times if only the application code changes. Next, model files are closely coupled with app code, so we include them after schemas to ensure a separate caching layer, and model downloads aren't repeated unnecessarily (which is time-consuming). Finally, placing the application code last suggets its higher likelihood of frequent updates, so changes to the code do not invalidate the cache for the earlier layers.
(See https://github.com/Shared-Reality-Lab/IMAGE-server/tree/main/preprocessors for examples)