Running Drupal in Docker 🌱

What is Drupal?

Drupal is content management software. It's used to make many of the websites and applications you use every day. Drupal has great standard features, like easy content authoring, reliable performance, and excellent security. -https://www.drupal.org/about

Installing Docker

  1. Log into the Linux based device
  2. Run the following commands in the terminal
    # install prerequisites
    sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y
    # add docker gpg key
    curl -fsSL https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release)/gpg | sudo apt-key add -
    # add docker software repository
    sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release) $(lsb_release -cs) stable"
    # install docker
    sudo apt install docker-ce docker-compose containerd.io -y
    # enable and start docker service
    sudo systemctl enable docker && sudo systemctl start docker
    # add the current user to the docker group
    sudo usermod -aG docker $USER
    # reauthenticate for the new group membership to take effect
    su - $USER

Running the Drupal Container

  1. Now that Docker is installed, run the following commands to setup the Drupal Docker container and run it
    # create working directories
    mkdir ~/docker/drupal -p && mkdir ~/docker/mariadb -p
    # set ownership on the working directories
    sudo chown "$USER":"$USER" ~/docker -R
    # create containers network
    docker network create containers
    # run the mariadb docker container
    docker run -d --name mariadb -e MYSQL_ROOT_PASSWORD=r00tp@$$ -e MYSQL_USER=drupal_rw -e MYSQL_PASSWORD='Dru4@l!!' -e MYSQL_DATABASE=drupal -v ~/docker/mariadb:/var/lib/mysql --network containers --restart unless-stopped mariadb
    # initialize the drupal application files
    docker run --rm drupal tar -cC /var/www/html . | tar -xC ~/docker/drupal
    # make a copy of default.settings.php
    cp ~/docker/drupal/sites/default/default.settings.php ~/docker/drupal/sites/default/settings.php
    # create the files directory
    mkdir ~/docker/drupal/sites/default/files
    # allow the container to write to files/ and settings.php
    sudo chmod a+rwx -R ~/docker/drupal/sites/default/files
    sudo chmod a+rwx -R ~/docker/drupal/sites/default/settings.php
    # run the drupal docker container
    docker run -d --name=drupal -p 8880:80 -v ~/docker/drupal/modules:/var/www/html/modules -v ~/docker/drupal/profiles:/var/www/html/profiles -v ~/docker/drupal/sites:/var/www/html/sites -v ~/docker/drupal/themes:/var/www/html/themes --network containers --restart unless-stopped drupal
  2. Open a web browser and navigate to http://DNSorIP:8880
  3. The Drupal setup screen should be displayed
  4. Select a language > Click Save and continue
  5. Select the Standard profile > Click Save and continue
  6. Enter the database name, username and password > Expand Advanced and set the Host value to mariadb (the mariadb container name) > Click Save and continue
  7. Create a site title and Drupal login > Click Install Drupal
  8. When the installation completes, enter a site name, email address, username and password > Click Save and continue
  9. Welcome to Drupal

Documentation: https://hub.docker.com/_/drupal