diff --git a/docs/_includes/snippets/core-container.rst b/docs/_includes/snippets/core-container.rst new file mode 100644 index 00000000..4e1a1a3a --- /dev/null +++ b/docs/_includes/snippets/core-container.rst @@ -0,0 +1,19 @@ ++---------------------------+-------+----------+----------------+ +| Container | Name | Hostname | IP Address | ++===========================+=======+==========+================+ +| DNS | bind | bind | 172.16.238.100 | ++---------------------------+-------+----------+----------------+ +| PHP | php | php | 172.16.238.10 | ++---------------------------+-------+----------+----------------+ +| Apache, Nginx | httpd | httpd | 172.16.238.11 | ++---------------------------+-------+----------+----------------+ +| MySQL, MariaDB, PerconaDB | mysql | mysql | 172.16.238.12 | ++---------------------------+-------+----------+----------------+ +| PostgreSQL | pgsql | pgsql | 172.16.238.13 | ++---------------------------+-------+----------+----------------+ +| Redis | redis | redis | 172.16.238.14 | ++---------------------------+-------+----------+----------------+ +| Memcached | memcd | memcd | 172.16.238.15 | ++---------------------------+-------+----------+----------------+ +| MongoDB | mongo | mongo | 172.16.238.16 | ++---------------------------+-------+----------+----------------+ diff --git a/docs/intermediate/best-practice.rst b/docs/intermediate/best-practice.rst index 1ee7efda..6a5ba6da 100644 --- a/docs/intermediate/best-practice.rst +++ b/docs/intermediate/best-practice.rst @@ -74,19 +74,11 @@ PHP project hostname settings ============================= When configuring your PHP projects to use MySQL, PostgreSQL, Redis, Mongo and other services, -make sure to set the hostname of each of those services to ``127.0.0.1``. +make sure to set the hostname/address of each of those services to how they are defined within the +Devilbox network: -**Why is that?** +.. include:: /_includes/snippets/core-container.rst -The PHP container port-forwards each service port to its own listen address on ``127.0.0.1``. -The Devilbox also exposes each of those service ports to the host operating system on ``127.0.0.1``. - -This allows you to keep your project configuration unchanged and have the same behaviour inside the -PHP container and on your host operating system. - -.. important:: - Do not mix up ``localhost`` with ``127.0.0.1``. They behave differently! - Use ``127.0.0.1`` and do not use ``localhost``. As an example, if you want to access the MySQL database from within the PHP container, you do the following: @@ -101,10 +93,11 @@ following: host> ./shell.sh # Enter the MySQL console - php> mysql -u root -h 127.0.0.1 -p + php> mysql -u root -h mysql -p mysql> -The very same command applies to access the MySQL database from your host operating system: +To access the MySQL database from your host operating system you would need the address to what it +exposes to on your host (usually ``127.0.0.1``): .. code-block:: bash :emphasize-lines: 2 @@ -113,17 +106,14 @@ The very same command applies to access the MySQL database from your host operat host> mysql -u root -h 127.0.0.1 -p mysql> -So no matter if you use the Devilbox or have another LAMP stack installed locally on your host -operating system, you do not have to change your configuration files if you stick to this tip. - -So any of your projects php files that configure MySQL as an example should point the hostname -or IP address of the MySQL server to ``127.0.0.1``: +Any of your projects php files that configure MySQL as an example should point the hostname +or IP address of the MySQL server to ``mysql``: .. code-block:: php mysql -h 127.0.0.1 + host> mysql -h 127.0.0.1 -u root -p # Access MySQL from within the PHP container - devilbox@php-7.0.19 in /shared/httpd $ mysql -h 127.0.0.1 - -.. important:: - Do not use ``localhost`` to access the services, it does not map to ``127.0.0.1`` on - all cases. + devilbox@php-7.0.19 in /shared/httpd $ mysql -h mysql -u root -p So when setting up a configuration file from your PHP project you would for example use -``127.0.0.`` as the host for your MySQL database connection: +``mysql`` as the host for your MySQL database connection: .. code-block:: php -Imagine your PHP framework ships a command line tool to run database migration. You could run -it from your host operating system or from within the PHP container. It would work from both -sides as the connection to the database is exactly the same locally or within the container. - -You could also even switch between the Devilbox and a locally installed LAMP stack -and still use the same configuration. - -.. important:: - The mapping of ``127.0.0.1`` to your host operating system does not work with - Docker Toolbox out of the box. In order to achieve the same behaviour read up on: - :ref:`howto_docker_toolbox_and_the_devilbox`. - Port mappings ------------- @@ -283,7 +248,5 @@ Checklist 2. You know how to become root inside the PHP container 3. You know how to leave the container 4. You know that file and directory permissions are synronized -5. You know that ``127.0.0.1`` is available on your host and inside the PHP container -6. You know that ports are the same inside the container and on your host os -7. You know that project urls are available inside the container and on your host -8. You know about the limitations of :ref:`howto_docker_toolbox_and_the_devilbox` +5. You know by what hostnames you can reach a specific service +6. You know that project urls are available inside the container and on your host diff --git a/docs/readings/available-container.rst b/docs/readings/available-container.rst index f87b026d..f78e2361 100644 --- a/docs/readings/available-container.rst +++ b/docs/readings/available-container.rst @@ -18,25 +18,7 @@ Core container These container are well integrated into the Devilbox intranet and are considered core container: -+---------------------------+-------+----------+----------------+ -| Container | Name | Hostname | IP Address | -+===========================+=======+==========+================+ -| DNS | bind | bind | 172.16.238.100 | -+---------------------------+-------+----------+----------------+ -| PHP | php | php | 172.16.238.10 | -+---------------------------+-------+----------+----------------+ -| Apache, Nginx | httpd | httpd | 172.16.238.11 | -+---------------------------+-------+----------+----------------+ -| MySQL, MariaDB, PerconaDB | mysql | mysql | 172.16.238.12 | -+---------------------------+-------+----------+----------------+ -| PostgreSQL | pgsql | pgsql | 172.16.238.13 | -+---------------------------+-------+----------+----------------+ -| Redis | redis | redis | 172.16.238.14 | -+---------------------------+-------+----------+----------------+ -| Memcached | memcd | memcd | 172.16.238.15 | -+---------------------------+-------+----------+----------------+ -| MongoDB | mongo | mongo | 172.16.238.16 | -+---------------------------+-------+----------+----------------+ +.. include:: /_includes/snippets/core-container.rst Additional container