DEV Community

Hasbi Hamza
Hasbi Hamza

Posted on

[Series] Drupal Env using docker & nginx - 3!

In the Previous article we were able to create our stack based on docker containers, and we discussed how to configure each container as a seperate service.
In this last chapter we need to get our Drupal application up and running.

First thing we need to understand how we can connect the containers over the network, previously in a the spoiler alert i've mentionned the use of the network key in our docker-composer which defines a bridge network that gives the containers the ability to communicate with each other using predefined IP adress Bridge NetWork (i've opted for the use of a bridge network with static IP mapping so we can easily understand how the communication is done) ...So each service will have a well defined IP adress by which we can target its container.

Alt Text

With that being set now let's test our Drupal app :

- For drupal dev we need to set our database configuration in the appropriate settings.php :

$databases['default']['default'] = array (
  'database' => 'db_name',
  'username' => 'root',
  'password' => 'root_password_defined_in_mariadb_container',
  'prefix' => '',
  'host' => 'name_of_the_mariadb_service_OR_IPAdress',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
); 
Enter fullscreen mode Exit fullscreen mode

As a result let's visit the admin dashboard to check if the configuration is working :

Alt Text

- Next thing we'll set the cache system to use our Memcache container :

// Memcache
$settings['memcache']['servers'] = ['IPADRESS:11211' => 'default'];
$settings['memcache']['bins'] = ['default' => 'default'];
$settings['memcache']['key_prefix'] = 'choose_your_key_prefix';

// Set default cache storage as Memcache and excludes database connection for cache
$settings['cache']['default'] = 'cache.backend.memcache';
$settings['cache']['bins']['render'] = 'cache.backend.memcache';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.memcache';
// Enables to display total hits and misses
$settings['memcache_storage']['debug'] = TRUE;
Enter fullscreen mode Exit fullscreen mode

Now let's check if Memcached service is working and well connected to Drupal .
Alt Text
Alt Text

Now we are all set with our Docker environment !
All the services are up and running i've added a Bonus script to start the stack automatically you just need to have Docker and docker-compose installed and TADAAA!

Code can be found here.

Top comments (0)