Docker containers: how do they work together?
- How does the nginx-container know about the php-container?
Under
links
you listed themy-php
container, this, among other things, creates a mapping between the name of the container and it's IP in the/etc/hosts
file.
- When PHP is invoked from nginx, which container does the PHP process run in?
As you would expect, any
php
code will run in themy-php
container, this is defined in thenginx
config file, which passes the processing of requests to thephp
engine running onmy-php:9000
.
- How is the data passed from nginx to PHP and back?
Over regular socket communication. Both dockers have their addresses, and they can communicate with each other, like any other computer connected to the network.
- Is this docker usage (3 containers for a simple web server application) the right way to use docker or is this an overkill of containers?
I only see 2 containers here. There are some who would say a container should only run one process (like here, so you have built the minimal system), and there are some who say each container should run whatever the service needs. (this however is a matter of preference, and there are different opinions on the matter)
- How can this docker architecture be scaled for increasing load? Can I use it for production?
Yes, you could use it for production. It can scale easily, but in order to achieve scale you are missing some pieces to balance the load. (e.g. a load balancer that can send new requests to an instance which isn't already busy. A very common tool for this is HAProxy.
- The containers use the same volume (./) on the host. When using a PHP Framework as Yii2, wouldn't it better to move the volume to either the PHP or Nginx container?
As the PHP container does all the processing in this case, it should be safe to only mount the volume on
my-php
.