Docker, part two. Semi-automatic rifle with homing leg

  • Tutorial
Please start reading from the beginning of the series: habrahabr.ru/post/267441

How not to use Docker.



To understand this article, you need to know the basic Dockerfile commands for creating images and the principles of object-oriented design.

I open the documentation of any official image of service software - for example, Nginx and find the section "How to use this image". We are offered to create our image on the basis of the official one by copying our files into it, configure the port mapping in the world, and mount your folder with configs.

FROM ...
COPY  . /usr/src/myapp
WORKDIR /usr/src/myapp

Yes, we are offered to inherit Model from View in one star class and pay for storing our proprietary applications on the Docker Hub. Business, as usual. They suggest that we do this in images of PHP, Pyhon, Ruby, and so on. Versions have been made for Python and Ruby with ONBUILD triggers for constructing heir images, which will be copied from the folder to the new image, “which should be all you need” - like 640 kilobytes.

Fortunately, the solution has long been known as a problem. Gang of four, Java creator James Gosling and Fowler have been saying for the past 20 years: use composition instead of inheritance. Therefore, I will put containers with different services nearby, create an adapter, data transfer object, and connect them through the config.

I use inheritance to extend existing functionality as part of encapsulation, taking into account the principle of Lisk substitution - for example, to connect to the php extensions I need and the system libraries that these extensions use.

Continuation can be found here.

Also popular now: