Open webprogrammierer opened 2 years ago
Here is how I use this project: under php and nginx containers I set volumes to - ./html:/var/www/html:cached (mapping host os subfolder html to containers /var/www/html).
Once container are up, I use composer inside php container to install drupal recommended project. This way all source files are availble on host os and docker container. Now, there might be performance impact d4d this way, but it works.
This may not even be recommended way using this project, but it works well for me.
Thank you, I will try this. But what do you mean with "d4d"?
This way you can edit your project file in Windows? And if the Docker container and volume is deleted, the source is still here in your windows path location?
And what about an existing Drupal project? How to copy all the files (themes, /site/default/files ...) into the container?
Oh, d4d is short for docker4drupal. Also, for my projects I only use docker-compose.yml and .env files. And make sure to stop containers (docker compose stop), and not "docker compose down" (this will delete db data).
For existing project I would suggest create drupal 8/9 project first, then copy your specific files (theme/modules) to it. Same goes for files. Also, I would suggest make db dump of your existing drupal projects and then import this db dump from within you php container. drush sql-cli < yourfile.sql
should work, or you could use mysql command (mysql -udrupal -pdrupal -hmariadb drupal < yourfile.sql).
I started docker4drupal with docker-compose up. Then in Docker Deskop I clicked on CLI link of my_drupal9_project_php to enter die PHP container.
Then I installed Drupal using composer. Everything was installed but the installation of Drupal core failed:
....
- Installing composer/semver (3.2.5): Extracting archive
- Installing asm89/stack-cors (1.3.0): Extracting archive
- Installing drupal/core (9.2.10): Extracting archive
- Installing drupal/core-recommended (9.2.10)
58/59 [===========================>] 98%^C
Install of drupal/core failed
wodby@php.container:/var/www/html $
How do you enter the container to install Drupal with composer inside the container?
From same folder where your docker-compose.yml is run:
docker compose exec php bash
That should puts you inside php container, you should be /var/www/html, and then running
composer create-project drupal/recommended-project ./
Just make sure you are in empty folder, composer will complain if there is any files.
docker compose exec php bash
is not a correct command
How is it correct?
Try using "docker-compose exec php bash" instead.
docker-compose exec php bash
or
docker exec -it <container id> /bin/bash
same result.
Now I am in the container:
wodby@php.container:/var/www/html $
Here I try to install Drupal like this (into subfolder drupal):
composer create-project drupal/recommended-project drupal
Everything gets installed, but not the core:
.....
- Installing doctrine/reflection (1.2.2): Extracting archive
- Installing composer/semver (3.2.5): Extracting archive
- Installing asm89/stack-cors (1.3.0): Extracting archive
- Installing drupal/core (9.2.10): Extracting archive
- Installing drupal/core-recommended (9.2.10)
58/59 [===========================>] 98%
Stucks on core install.
I do not understand that.
Oh, I waitet for very long time, about 15 minutes the installation was stucked. Then the installation succeeded. 15 minutes to install drupal within a container? This is NOT okay.
That might be file sync between win and docker. Is there a way for you to use WSL only, and not use Docker Desktop. Install docker in WSL, that should be straightforward. I find linux to be the most easiest to work with when it comes to docker.
So after this succeeded I called http://drupal.docker.localhost:8000/core/install.php .
I get the same error as if I installed Drupal directly on windows:
Error: Call to a member function setFormClass() on null in system_entity_type_build() (line 1217 of /var/www/html/web/core/modules/system/system.module).
So there is no difference. I can install it on windows or in the container, same error message.
Drupal is NOT ready to be used in Docker containers using Windows as host system.
And now?
If I install docker in WSL then I will not be able to edit/change Drupal project files in Windows.
Why did you tell me to
I use composer inside php container to install drupal recommended project
if this does not work? There is no difference, same error message.
Still searching for a solution.
I now tried to install docker4drupal NOT into the container (as you said) but into WSL:
Starting with this command in my Windows Console (Cmder):
wsl ~
mkdir htdocs
cd htdocs
composer create-project drupal/recommended-project docker4drupal
cd docker4drupal
docker-compose up
explorer.exe .
Then install Drupal. I do not use docker-compose.override.yml.
The "explorer.exe . " command within the docker4drupal folder opens Windows Explorer in \wsl$\Ubuntu\home\SOMEUSR\htdocs\docker-drupal
And this is the most important thing: In Windows the path must start with: \wsl$... oder \wsl$\Ubuntu..
So docker4drupal with Drupal 9 is installed within the WSL 2. But in my Docker Desktop Windows App i can still see all the containers for this docker-drupal installation.
And I can edit all Drupal files and project files directly in Window using the path \wsl$\Ubuntu\home\SOMEUSR\htdocs\docker-drupal
So the installation of a new Drupal project succeeded. Next I will install an existing Drupal Docker project (use existing docker image, clone Drupal source code from git ...).
Off topic: Do you know the answer to this question?
@webprogrammierer I do it this way: both -compose
and -compose.override
, letting d4d install Drupal itself. I modify the first to include my volumes:
volumes:
- ./:/var/www/html:cached
- ./siteroot/libraries:/var/www/html/web/libraries
- ./siteroot/modules:/var/www/html/web/modules
- ./siteroot/profiles:/var/www/html/web/profiles
- ./siteroot/sites:/var/www/html/web/sites
- ./siteroot/themes:/var/www/html/web/themes
I have a siteroot
folder in the project root, it contains the five folders above. I can put my own modules (both my custom ones and the contrib ones I install) and themes here and the volumes will map them to Drupal all right. I can edit my source files in an IDE (PhpStorm, VS Code, whatever) by simply using the network paths in Windows:
\\wsl$\Ubuntu\home\...\siteroot\modules\custom\my-module
This way Drupal is brought in by d4d, upgraded when there's a new version, and my own files are there available from Windows.
By the way, don't forget to add the same to nginx
or apache
and any other container that needs them, too.
Hello
I use composer inside php container to install drupal recommended project
I have exicuted composer inside php container but still same error message
Error: Call to a member function setFormClass() on null in system_entity_type_build() (line 1217 of /var/www/html/web/core/modules/system/system.module).
Any solution to resolve this issue is higly appriciate! Thank you!
@mahaprasadpeddapeli Try this solution https://www.drupal.org/forum/support/post-installation/2017-04-20/fatal-error-call-to-a-member-function-setformclass#comment-14275746 and also check if you correctly added the volume path to the www/html.
Also the fact it is windows, so you might have to try to run this from different terminal like cygwin or wsl above, normal windows prompt will not work
I am using Windows 10 Pro, Docker Desktop, WSL 2, Hyper-V (if needed).
If I install docker4drupal without the docker-compose.override.yml file, I get errors like here (issue 492), Drupal is NOT working.
If I install docker4drupal with the docker-compose.override.yml file includes, Drupal can be started, installed and is working. But in this case my Drupal project files are NOT shared between the Container/Linux and Windows. So I am not able to edit and change my project files (e.g. theme files, css files, ...) in Windows using the Windows Explorer and an normal Editor or some Windows IDE.
This is not accptable. Other Docker containers (docker-tutorial, ...) can be shared between Linux and Windows without problems. WHY NOT this Drupal Project? What is the problem?
How can this be solved: Use docker4drupal container, edit and change files directly on Windows?
Thank you very much.
PS: Here I found a lot of issues, all having exactly the same problem!