0
votes

I am trying to dockerize Drupal 8. One thing which I couldn't wrap my head around is making customizations available to new containers. For instance, I have downloaded Bootstrap theme in my dockerfile and it shows under Appearance > Uninstalled themes. And I can Install and set it as default from admin UI. However, I don't want my docker image/container users to deal with this instead it should be installed by default when they run the container.

Is there any way to achieve this?

Here is my Dockerfile:

FROM drupal:8.9.13
RUN cd /opt/drupal/ \
    && composer require drupal/bootstrap:^3.23 \
    && composer install \ 
    && chown www-data:www-data -R /opt/drupal/web/themes 

P.S. I'm new to Drupal workloads.

2

2 Answers

0
votes

You can add drush via composer inside your docker file: composer require --dev drush/drush and call drush bin using its vendor dir ./vendor/bin/drush command. Now to set the default theme use the following command: ./vendor/bin/drush config-set system.theme default bootstrap.

The optional things that could be done are also ./vendor/bin/drush en bootstrap and ./vendor/bin/drush cr - to clear the cache if the theme default theme won't show at first time. You have to check if it's needed.

Credits go to: 1 and 2

0
votes

Installing modules with composer is very different from installing them in Drupal. In order to install a module in Drupal you need access to the database with a working installation. The problem is that anything in the Dockerfile is part of the build process - which is used for creating an image that is finally run via CMD. Now, I'm not familiar with the official Drupal Docker image but I'm sure it must be a simple PHP based container? The point being is that the last thing to happen is for PHP to actually be run, and until that point, MySQL is not running.

How to achieve what you desire very much depends on how you install Drupal after Docker has finished building? Ideally, you're doing this with an ENTRYPOINT script rather than manually - and if so, then after the install - enable the theme with Drush there. Ideally, you should just make your own distribution profile and this would enable the theme for the user on site-install (and allow you to make all your customisations in one place).

On the other hand, if part of what you're doing is scripted - then you probably just need to add a Drush alias so Drush is able to locate your installation when a command is run outside of webroot; see https://github.com/drush-ops/drush/blob/master/examples/example.site.yml but you haven't said how you're installing Drupal so I can't say for sure.