Z
Z
Zudwa2017-10-06 14:57:27
Docker
Zudwa, 2017-10-06 14:57:27

How to understand docker if nothing is clear?

How to understand docker if nothing is clear?
I don't understand how the development environment should be organized.
Do I need to create a separate image for each component (php, nginx, DB)? If so, how should they interact with each other?
For example, if I have a separate image for the database, how should I connect to it?
And how to work with the code? Do I understand correctly that the code should be stored locally with me and when I turn on the docker, the local folder will be mounted in the container and when the code changes, the changes will be immediately visible in the browser?
Maybe there is some kind of manual for the completely stupid, where this is all explained in an accessible way?
It seems to be roughly clear in words how it works, but when I try to do all this, I fall into a stupor and it’s not clear where to start.
PS Habr with his "understanding docker" and "understanding Docker" read. Documentation too. But it feels like everything is told superficially, taking into account the fact that everything is already clear from the very beginning.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexander Talalaev, 2017-10-07
@neuotq

With Docker, everything is simple, you just need to turn the established logic in your brain a little.
The main essence and idea is the launch of each application (php, mysql, etc.) in its own container. At the same time, php itself will think that it is running as always in a normal full-fledged OS. Therefore, the container is assembled in such a way as to satisfy the minimum requirements of the program that it will contain.
This is how you launch a bunch of containers and you get a dry cargo ship (the docker has a whale there) with containers. Why is this all? To facilitate administration and software updates, as well as to minimize costs in case of glitches / crashes of any program.
All containers are as independent as possible from each other, while there is a mechanism when the container is jealous of another. For example, the phpmyadmin container, it makes no sense to run it without a mysql or mariadb container, it will not work.
Communication occurs mainly through the network, the internal network rises. Also, of course, through the disk, everything is provided.
When everything is done right, the system administrator is relieved of the enormous work of tracking updates, the compatibility of these updates, and so on.
You need a version of php5.6, launched a container with it, you need php7.1, launched it, and you don’t need any adventures with updating a bunch of packages, possible conflicts with other necessary programs, and so on.
Scaling issues are also conveniently solved, small convenient bonuses for additional automation appear, the risks of OS crashes as a whole are reduced, if only the container crashes, etc., etc., as a result, there is a real opportunity for even small projects to achieve near zero downtime.
Here's another listen Kirill Mokevnin from Hexlet is trying to explain in understandable language 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 Docker, this is the key to understanding everything else.
PS By the way, I highly recommend Hexlet, they are probably the best in Runet for novice programmers

P
planc, 2017-10-06
@planc


Do I need to create a separate image for each component (php, nginx, DB)?
there are official images on the docker hub
to build everything together you need docker-compose
For example, if I have a separate image for the database, how should I connect to it?
when creating, name the container --name
docker run --rm -it --name deb1 debian bash
and link the second container
docker run --rm -it --name deb2 --link deb1 debian bash
now the second container can talk to the first one named deb1
And how to work with the code?
use volume( -v option)
on host file:
echo 'hello world' > /tmp/yo.txt
create container
docker run --rm -it -v /tmp/yo.txt:/tmp/yo.txt debian bash
and now we have access to this file in the container
Maybe there is some kind of manual for the completely stupid, where this is all explained in an accessible way?
https://docs.docker.com/get-started/

D
DarkMode, 2017-10-08
@DarkMode

Here are a couple of sites that will come in handy when learning docker.
https://www.katacoda.com/courses/dockerlabs.play-with-docker.com
_

V
Vladimir Kuts, 2017-10-06
@fox_12

> Do I need to create a separate image for each component (php, nginx, DB)?
you need - so it will be easier for you than to keep everything in one
. For example, if I have a separate image for the database, how should I connect to it?
Through links, for example. If you linked an image with a database as db to the php container, then it will be visible in the php container as db. And for example, you simply access the mysql database as db:3306

A
Alorian, 2017-10-12
@Alorian

Here I wrote in sufficient detail about local development on docker (windows)
https://verstaem.com/devops/docker-php-development/
The usual docker-compose is used. On the dev server, it will also be enough, the same compose file can be run in a Linux environment on a full-fledged server, no longer locally.
Most of the article is about the interaction of the host and the virtual machine with the docker.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question