Setting up Moodle Docker on Windows

Setting up Moodle Docker on Windows

by Amanda Doughty -
Number of replies: 6
Picture of Core developers Picture of Plugin developers

Does anybody have a set of instructions for setting up https://github.com/moodlehq/moodle-docker on a Windows machine and running Behat tests? Asking for a friend.

I am absolutely useless on Windows. 

Average of ratings: -
In reply to Amanda Doughty

Re: Setting up Moodle Docker on Windows

by Sébastien Mehr -

Hello,

It's a little bit tricky but you can use docker containers for Moodle on Windows with WSL :

  1. Install WSL
  2. Install your Linux distribution of choice (i use ubuntu)
  3. Install Docker client for Windows
  4. Install Docker on your WSL distribution
  5. Enable Docker client integration with your distro (Settings > Resources)
  6. Deploy Moodle containers in your WSL distribution
  7. If needed, you can browse your WSL distribution on Windows explorer with this path : \\wsl$\Ubuntu\home\

To edit wsl distribution files from windows, i recommand to use VSCode with the WSL extension.

Have fun smile

Seb

Average of ratings: Useful (2)
In reply to Sébastien Mehr

Re: Setting up Moodle Docker on Windows

by Amanda Doughty -
Picture of Core developers Picture of Plugin developers
Thanks for the reply Seb. I am currently stuck on 2. I have tried all sorts of troubleshooting but i just keep getting the error 'pur-inventory never augmented'. I suspect it has something to do with the way the Microsoft store is managed on my work PC.
In reply to Amanda Doughty

Re: Setting up Moodle Docker on Windows

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
I use VirtualBox instead to run a virtual Ubuntu which can then run Docker and Behat tests (with and without Docker) etc. So a self contained machine that's sandboxed away from Windows.
Average of ratings: Useful (1)
In reply to Amanda Doughty

Re: Setting up Moodle Docker on Windows

by Neill Magill -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
I use a batch file to start it (to save myself having to type all the environment variables):

@ECHO OFF
# Setup the environment variables
SET MOODLE_DOCKER_DB=mysql
SET MOODLE_DOCKER_WWWROOT=D:\moodlesource\moodlefordocker
SET MOODLE_DOCKER_SELENIUM_VNC_PORT=5900
SET MOODLE_DOCKER_BROWSER=chrome
SET MOODLE_APP_VERSION=latest
# Puts the config file into Moodle
copy /y config.docker-template.php %MOODLE_DOCKER_WWWROOT%\config.php
# Starts docker
bin\moodle-docker-compose up -d

After that you can use the normal commands (with slashes changed for the windows parts from the instructions in the readme) for example

bin\moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php

If you are not using the WSL version of docker it is much harder to get docker to actually start from what I remember (i.e. it required you to run some kind of docker-machine command to get the proper environment variables setup on Windows so that you could connect to the VM running docker)

I don't recall installing any specific Linux distro to get things to work with newer versions of Docker on Windows (but since I do mount windows directories into Docker it is probably not as fast as it could be)

Average of ratings: Useful (3)
In reply to Neill Magill

Re: Setting up Moodle Docker on Windows

by Amanda Doughty -
Picture of Core developers Picture of Plugin developers
Thank you Neill. I did try this but it takes my machine all day to run any of the tests!
In reply to Amanda Doughty

Re: Setting up Moodle Docker on Windows

by Neill Magill -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Yeah running behat can take a while, especially if you are running the full Moodle suite.

You can limit the tests you run by targeting for example a specific behat file (or if you use tags specific tags)

For example adding:

--tags="@mod_forum"

would only run tests tagged as part of the forums. We have a specific tag on all of our custom plugins so we can run just those tests.

or 

/path/to/moodle/mod/myplugin/tests/behat/testsomething.feature

to target a specific file.

It is possible to do similar things for phpunit as well, I imagine that most of the time when running on our dev systems this is what we want to do..
Average of ratings: Useful (1)