📜 ⬆️ ⬇️

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

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 the 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, setting up a port mapping to the world, and mounting our folder with configs.

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

Yes, we are offered to inherit the Model from View in one star class and pay for storage on Docker Hub of the images of our proprietary applications. Business, as usual. This is what we are offered to do in images of PHP, Pyhon, Ruby, and so on. For Python and Ruby, even versions with ONBUILD triggers to build hereditary images were made, with which the application from the folder will be copied into a new image, “which should be all you need” - like 640 kilobytes.

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

Inheritance I use to extend the existing functionality in the framework of encapsulation, taking into account the Liskov substitution principle - for example, to connect to php the extensions I need and the system libraries that these extensions use.

Continuation can be found here.

Source: https://habr.com/ru/post/267451/


All Articles