Docker4Drupal - Mount with existing Drupal

This is meant for existing Drupal projects made with drupal-composer/drupal-project.

  1. Download/unpack docker4drupal source code from the latest release
  2. Copy docker4drupal to site folder with cp -a docker4drupal/. your-drupal-folder/
  3. Enter your-drupal-project-folder and delete docker-compose.override.yml as it's used to deploy vanilla Drupal
  4. Ensure NGINX_SERVER_ROOT (or APACHE_DOCUMENT_ROOT) is correct on your docker-compose.yml, by default set to /var/www/html/web for composer-based projects where Drupal is in web subdirectory
  5. If you want to import your database, uncomment the line for mariadb-init bind mount in your docker-compose.yml file. Create the directory ./mariadb-init in the same directory (mkdir mariadb-init) and put there your .sql .sql.gz .sh file(s). All SQL files will be automatically imported once MariaDB container has started.
  6. Ensure database access settings in your settings.php corresponds to values in .env file, e.g.:

    $databases['default']['default'] = array (
      'database' => 'drupal', // same as $DB_NAME
      'username' => 'drupal', // same as $DB_USER
      'password' => 'drupal', // same as $DB_PASSWORD
      'host' => 'mariadb', // same as $DB_HOST
      'driver' => 'mysql',  // same as $DB_DRIVER
      'port' => '3306', // different for PostgreSQL
      'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', // different for PostgreSQL
      'prefix' => '',
    );
    
  7. Run docker-compose up -d to start containers.

  8. If needed, run composer install with docker-compose exec php composer install
  9. That's it! Proceed with Drupal installation at http://drupal.docker.localhost:8000
  10. If you have trouble to access it, try to configure domains
  11. You can see status of your containers and their logs via portainer: http://portainer.drupal.docker.localhost:8000

Default database user, password and database name are all drupal, database host is mariadb.