Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

community creator

How to run a drupal application using docker & nginx

Hasbi Hamza

In my previous shot, created our stack based on docker containers and discussed how to configure each container as a separate service. In this shot we will get our Drupal application up and running.

The first thing we need to understand is how to connect containers over a network. Previously (in the spoiler alert I included at the end of my previous shot), I mentioned the use of the network key in our docker-composer that defines a bridge network that gives the containers the ability to communicate with each other using the predefined IP address 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 address that we can use to target its container.

With that being said, 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',

As a result, let’s visit the admin dashboard to see if the configuration is working:

Next, 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;

Now let’s check if Memcached service is working and well connected to Drupal .

Now, all the services are up and running, and we are set with our Docker environment!

Bonus: 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.


community creator

View all Courses

Keep Exploring