DockerFile optimization

Combining the wisdom of various predecessors, combined with his understanding, to make it easier to understand

Their finishing biased in favor of streamlining the theory, detailed points of reference this article

Why optimization and optimal allocation

  • Construction of increasing the speed of the mirror
  1. Unwanted files out of the build directory mirroring, or write .dockerignore file
  2. Container only run a single application, such as site architecture lnmp, of course, all of these can be run to a container, but if these run separately to each container, modular easy call
  3. The easy to change the configuration file into the back, because every building, every altered after the cache of all to be rebuilt
  4. Try to specify the label, do not use the latest, latest is the default label, but the label is updated frequently and sometimes change, then representing the entire mirrored cache will need to be rebuilt.
  5. After each run a command, delete unnecessary files
  6. Try using a binary installation package, the installation can reduce dependence, thereby reducing the volume and speed
  • Reducing the volume mirroring docker
  1. Select base image volume is relatively small, in general, the official mirrors are relatively good
  • Construction of reducing mirror layer
  1. As the number of RUN command, command related && possible to connect, to reduce the mirror layer
  • Increase readability
  1. Add the necessary comments

Guess you like

Origin www.cnblogs.com/joinbestgo/p/11237175.html