Speaker
Dmitry Figol
Material
Note
- Docker Concept
 

- Optimize Goal
- Reducing image size
 - Reducing build time
 
 - Priority
- Fast build during development → Use slim-stretch
 - Small size during production → Use alpine
 
 
build deps are only needed when compiling but not runtimeImprovement
- Use specific 
COPYstatement instead ofCOPY .. .dockerignore
delete build deps doesn't shrink image size
- Docker Layer
- Instructions create read-only layers
 - A new layer can't be smaller than the previous layer
 - Layers are cached and can be re-used for subsequent builds
 - Layers introduce some overhead
 
 - Tips
- Combine multiple RUN statements into one
 - delete files in the same layer (instruction) where they were added
 - arrangement statement from the least changing to the most changing (system-level -> tools -> Python deps -> source code)
 - don't save deps to cache
- pip: 
--no-cache-dir - apk: 
--no-cache 
 - pip: 
 
 
complicate Dockerfile and no cache during build
- Docker multi-stage
- Build an intermediate image with all build deps and install your app
 - Copy the result to a fresh image
 
 
Other Tips
- Bind mount source code instead of COPY in local dev env
 PYTHONUNBUFFERED=1-> print to stdout without bufferingPYTHONDONTWRITEBYTECODE=1-> no*.pycfiles