serve icon indicating copy to clipboard operation
serve copied to clipboard

Optimized dockerfiles using docker best practices

Open chauhang opened this issue 6 years ago • 1 comments

Reduce the size of the docker containers, use multi-stage builds and other recommended best practices from Docker for optimized dockerfiles

  • [ ] Multi-stage builds
  • [ ] Use Docker build-kit
  • [ ] Use optimized base image for production deployments (eg alpine linux or docker python base image)
  • [ ] Scan image for security vulnerabilities and ensure all checks are green

chauhang avatar Apr 10 '20 01:04 chauhang

Reduce the size of the docker containers, use multi-stage builds and other recommended best practices from Docker for optimized dockerfiles

  • [ ] Multi-stage builds
  • [ ] Use Docker build-kit
  • [ ] Use optimized base image for production deployments (eg alpine linux or docker python base image)
  • [ ] Scan image for security vulnerabilities and ensure all checks are green

Optimization in torchserve imaage size with the base image as ubuntu 18.04 [which takes around 63MB + updates] -

  1. Remove unnecessary build tools and install PyPI torch serve instead of local build
  • Size reduces from 2.81GB to 2.09GB
  1. Use two-stage build i.e. compile and runtime + torchserve from pypi [as described above]
  • Size reduces from 2.09GB to 1.95GB

Considering the fact that torch itself takes around a GB + python and java [light weight JRE] dependency, the above number, looks optimal.

For further optimization, we will have to change the base image suggested by @chauhang i.e. by using either alpine or Debian based slim python etc. as the base image.

@chauhang @fbbradheintz @lokeshgupta1975 - As of now, we have majorly certified it on Ubuntu. Introducing base image as alpine or Debian based slim python, etc. may further reduce the image size however this may also result in more efforts for certification w.r.t. performance etc.. I will try to get size using alpine [if works] and slim python etc.

TL;DR

torchserve image layers as as result of executing 'dive' utility

NOTE -- layer with size 1.5GB is a pytorch layer

Screen Shot 2020-05-06 at 10 42 53 PM

codinnvrends avatar May 06 '20 17:05 codinnvrends