Drupal docker11/19/2023 ![]() Being able to set our containers' environment variables is one of the best benefits of using Docker. You may have also noticed that we defined the environment option in a similar way as what we did in the database service. Instead of using an existing image, like what we did with the database service, we want to use our own Dockerfile to build the Drupal container, which we've defined earlier. For this setup, our database files will be located in the data sub-directory of the application root. If the container is destroyed or rebuilt, our database is safe since it resides in the host machine. This lets us persist the database by mounting a path located in the host machine into the container. Furthermore, the image already allows us to set certain settings necessary for our application, such as the database credentials, without the need to further extend and customize the image.Īnother option worth noting is the volumes option. In the spirit of reusing existing solutions where possible, we use the latest official MariaDB Docker image instead of creating a custom image of the database ourselves. :/var/www/html restart : always environment : MYSQL_DATABASE : drupal MYSQL_USER : drupal MYSQL_PASSWORD : drupal MYSQL_HOST : db Copy Copied!įrom the code, you might have guessed that we have 2 services - one that serves our application( drupal) and a database service ( db). data:/var/lib/mysql restart : always environment : MYSQL_ROOT_PASSWORD : root MYSQL_DATABASE : drupal MYSQL_USER : drupal MYSQL_PASSWORD : drupal # The Drupal service. Version : '3.3' services : # The database service. It does so via a YAML file where we define and configure the necessary services that our application needs.įor our setup, our Compose file, named docker-compose.yml, looks like this: If you haven't come across, Docker Compose basically allows you to piece together multiple containers that work together to form your application. Now that we have our basic Dockerfile to define our Drupal container, we then need to define other services that we'll need for our application, such as a database service, by sourcing other containers. This also allows us to use drush commands properly from inside the container.įinally, since we're using the Composer template, Drupal will be located under the web sub-directory so we'll need to make a minor adjustment to the default DocumentRoot that comes with most Debian-based OS. Install mariadb-client so that we can connect to the database using the command line from inside the container. Use the latest official Docker image for Drupal. In summary, this Dockerfile does the following: This image installs the basic Drupal requirements as well as apply some recommended settings, which means less code for us too. RUN sed -i 's/DocumentRoot \/var\/VOLUME /var/www/html Copy Copied!Īs I've mentioned earlier, I aim to reuse existing solutions where possible so where better to start than to use the official Docker images for Drupal. RUN apt-get update & apt-get install -y mariadb-client git # Install Composer RUN curl -sS | php -install-dir=/usr/local/bin -filename=composer # Make a minor adjustment to the DocumentRoot so that it points to where our application codes are. Drupal imageįor this setup, we'll only need one Dockerfile, which will be used to build the main image for our Drupal container.įROM drupal:latest # Install MySQL client so we can use drush from inside the container, among other things. It also comes with sensible default packages, structure, and tools, such as drush and Drupal console. ![]() The template provides a starter kit for managing your site dependencies with Composer. ![]() This setup assumes that the Composer template for Drupal will be used. If you prefer to jump into the code, check out an example Drupal project I created that uses this approach. In doing so, I hope to provide a simple starting point for myself, and hopefully others as well, to build future projects on. The idea is to reuse and extend existing solutions while having minimal custom code as much as possible. I found a lot of great examples on how to leverage Docker for Drupal development, some of which I've used personally, so much so that I've decided to try and come up with the simplest and most straightforward setup I can. It lets you, and other developers, easily and consistently setup a local development environment anytime without the hassle of going through multiple steps and documentation, and most of all, provides a high degree of Environment Parity. Using Docker as part of your development environment is a smart and progressive move.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |