drupal-docker-installation
Install Drupal in docker
This guide will walk you through installing Drupal in a Docker container using Docker Compose.
Create drupal installation directory in /srv folder
mkdir drupal.example.com
Step 1: Create docker-compose file
Create a docker-compose.yaml file inside the /srv/drupal.example.com directory with the following content:
# Filename: /srv/drupal.example.com/docker-compose.yaml
# docker-compose file to start up Laravel drupal app in https://drupal.example.com
# to start the container run:
# docker-compose up -d
#
# Note: containrrr/watchtower service will auto update this container
version: "2.4"
name: drupal-example-com
services:
drupal:
image: rsubr/php-apache-ubuntu:focal
container_name: drupal.example.com
restart: always
volumes:
- ./www:/var/www/html
- ./www/public:/var/www/html
- ./etc/apache2/mods-enabled/mpm_prefork.conf:/etc/apache2/mods-enabled/mpm_prefork.conf:ro
- ./etc/php/7.4/apache2/conf.d/99-local.ini:/etc/php/7.4/apache2/conf.d/99-local.ini:ro
mem_limit: 8G
labels:
- com.centurylinklabs.watchtower.enable=true
- traefik.enable=true
- traefik.http.routers.drupal.rule=Host(`drupal.example.com`)
- traefik.http.routers.drupal.tls=true
- traefik.http.routers.drupal.tls.certresolver=lets-encrypt
depends_on:
- mysql
mysql:
image: mysql:5.7
container_name: drupal-mysql.example.com
restart: always
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
expose:
- 3306:3306
volumes:
- ./mysql-data:/var/lib/mysql
- ./mysql-conf/my.cnf:/root/.my.cnf
Create a .env file inside the /srv/drupal.example.com directory with the following content:
Run openssl rand -base64 16 in the command line to generate a new secure password.
# Mysql Database
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=drupal.example.com
MYSQL_USER=drupal.example.com
MYSQL_PASSWORD=
Create a mysql-conf directory in the /srv/drupal.example.com directory:
mkdir mysql-conf
Create a my.cnf file inside the /srv/drupal.example.com/mysql-conf directory with the following content:
# Filename: /srv/drupal.example.com/mysql-conf/my.cnf
[mysql]
user=root
password=
[mysqldump]
user=root
password=
Step 2: Download and extract Drupal
Create a www directory in the /srv/drupal.example.com directory for download and extract drupal project.
Follow the below docs to download and extract drupal project: Download and extract Drupal
Step 3: Create settings.php and the files directory
Follow the instructions to configure settings.php : Configuration
Also, set the base URL in /srv/drupal.example.com/www/sites/default/settings.php to https://drupal.example.com.
$base_url = 'https://drupal.example.com';
$cookie_domain = 'example.com';
Step 4: Run docker compose to deploy drupal
Run docker-compose up -d to deploy drupal.
Access Drupal Installation:
Open the web browser, navigate to drupal.example.com. Follow the on-screen instructions to complete the Drupal installation process. This typically involves configuring the database connection, specifying the site location, and creating the initial administrator account.