How to understand Docker, if you do not understand?

How to understand the Docker, if you do not understand?
I just can't understand how should be organized development environment.
Whether it is necessary for each component(php, nginx, DB) to create a separate image? If so, how they have each other to interact?
For example, if I have a separate image for the database, how am I supposed to connect to it?
And how to work with the code? Do I understand correctly that the code should be kept from me locally and when you turn the Docker local folder will be mounted in the container and when the code changes the changes will be immediately visible in the browser?
May be there is some guide for really stupid, where is it explained?
Like the words clear about how it works, but when trying to do it all, then fall into a stupor and not understand where to start.
P. S. Habr with his "understanding docker" and "realizing Docker" read. The documentation also. But feeling like everything is narrated superficially given the fact that initially all clear.
June 14th 19 at 18:31
5 answers
June 14th 19 at 18:33
With Docker, all just need only slightly turn the established logic in the brain.
The main essence of the idea is to run each application (php, mysql, etc.) in your container. While php itself will think that started as always in a OS. Therefore, the container is collected to meet the minimum requirements of the program which it will contain.
That's how you launch a bunch of kontenerow and you have a cargo ship(the Docker there's a whale) containers. Why all this? For ease of administration and updates, as well as to minimize costs in the glitches/drop any programs.
All containers are maximally independent from each other, while there is a mechanism when the container is depends on the other. For example, the container phpmyadmin, there is no reason to run without a container mysql or mariadb, does not work.
Communication takes place mainly through the network, rises the internal network. Also of course using the disk provided.
When done properly, with a system administrator removed a huge effort tracking updates, the compatibility of these updates, and so on.
You need the version of php5.6, launched container with it, we need php7.1, run it, it does not need any adventure with updating the heap of packages, possible conflicts with other needed programs and so on.
Also easier to solve the scaling issues, there are small handy bonuses for more automation , reduced risk of falling OS in General, falls if only the container, and so and so, as a result there is a real possibility even for small projects to achieve nearly zero downtime.
Here's another look Cyril Makinen from Hexlet trying-to-understand language to tell what it is and why. And by the way he focuses on understanding why it was necessary to think and what problems were solved when they came to the Docker, it's the key to understanding everything else.
PS by the way, and he Hexlet extremely advise, they are probably the best in Runet for beginners
June 14th 19 at 18:35

Whether it is necessary for each component(php, nginx, DB) to create a separate image?

on Docker hub is official images
to build all together need docker-compose


For example, if I have a separate image for the database, how am I supposed to connect to it?


when you create give a name to the container --name
docker run --rm -it --name deb1 debian bash
and linked with the second container
docker run --rm -it --name --link deb1 deb2 debian bash
now the second container can talk to the first named deb1


And how to work with the code?

use the volume (- v option)

on the host file:
echo 'hello world' > /tmp/yo.txt
create a container
docker run --rm -it-v /tmp/yo.txt:/tmp/yo.txt debian bash
and now we have the container have access to this file


May be there is some guide for really stupid, where is it explained?

https://docs.docker.com/get-started/
June 14th 19 at 18:37
Here are a couple of sites which will be useful in the study of Docker.
https://www.katacoda.com/courses/docker
labs.play-with-docker.com
June 14th 19 at 18:39
> Whether for each component(php, nginx, DB) to create a separate image?
need so you will be easier than to keep it all in one

For example, if I have a separate image for the database, how am I supposed to connect to it?
Using links for example. If prilinkovan to the container with php image from database db - it will be visible in the container as a php db. And database mysqlк example are treated just like db:3306
June 14th 19 at 18:41
Here is explained about the local development in the Docker (windows)
https://verstaem.com/devops/docker-php-development/
Use usual docker-compose. On the dev server too, it will be enough, the same compose the file can be in a Linux environment to run on a full server, not locally.

Most articles about the interaction between the host and the path with Docker.

Find more questions by tags Docker