Moodle in docker environent

Moodle in docker environent

дэргэд Steve Pelham -
Хариу нийтлэлийн тоо: 67

I have a docker environment comprised of 3 docker containers: 
php-fpm 
nginx 
mariadb 

I'm trying to install a moodle in that environment. The install process gets stuck at the php script "user/editadvanced.php". "user/editadvanced.php" looks like so:

erterz

If I fill in the form and click "Update Profile" and get:

zewt

If I click on "Skip to main content" i get redirected to "user/editadvanced.php". Loading "user/editadvanced.php" In the console of the browser I can see  "net::ERR_ABORTED 404 (Not Found)" for the file admin/index.php. That points to the line 33 (and lines 35 and 36) of user/editadvanced.php. In the line 33 the js-file "http://localhost:8080/lib/javascript.php/1723639906/lib/babel-polyfill/polyfill.min.js" is supposed to be loaded.

When I load  "http://localhost:8080/lib/javascript.php/1723639906/lib/babel-polyfill/polyfill.min.js" maunally it gets redirected to "user/editadvanced.php". That goes for each file that has "1723639906" in its path. Is "1723639906" a key or similar in connection with boost theme ? And if so, is it possibleUseful to disable it ?

How ever the prob remains. In the Logs of the nginx container I get in case of a reload of "user/editadvanced.php" the following logs:

172.18.0.1 - - [16/Aug/2024:15:44:37 +0000] "GET /theme/styles.php/boost/1723822570_1/all HTTP/1.1" 303 447 "http://localhost:8080/user/editadvanced.php?id=2" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
2024/08/16 15:44:37 [error] 33#33: *203 FastCGI sent in stderr: "PHP message: Cannot find session record ie731vdqrb20msjtss8lohpus4 for user 2, creating new session" while reading response header from upstream, client: 172.18.0.1, server: localhost, request: "GET /lib/javascript.php/1723822570/lib/polyfills/polyfill.js HTTP/1.1", upstream: "fastcgi://172.18.0.4:9000", host: "localhost:8080", referrer: "http://localhost:8080/user/editadvanced.php?id=2"
172.18.0.1 - - [16/Aug/2024:15:44:37 +0000] "GET /lib/javascript.php/1723822570/lib/polyfills/polyfill.js HTTP/1.1" 303 447 "http://localhost:8080/user/editadvanced.php?id=2" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"
2024/08/16 15:44:37 [error] 33#33: *188 FastCGI sent in stderr: "PHP message: Cannot find session record ie731vdqrb20msjtss8lohpus4 for user 2, creating new session" while reading response header from upstream, client: 172.18.0.1, server: localhost, request: "GET /lib/javascript.php/1723822570/lib/babel-polyfill/polyfill.min.js HTTP/1.1", upstream: "fastcgi://172.18.0.4:9000", host: "localhost:8080", referrer: "http://localhost:8080/user/editadvanced.php?id=2"

So this points to the session management. I made a php-test script for sessions. It files the session data correctly in the session path. So the path is writable. 
Do you have experiences on how to set up sessions in such a set up ?

Thanks for any help, hint etc.

Best,

Steve

Үнэлгээний дундаж: -
Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
My development environment uses Docker (nginx, php-fpm, Mariadb and Redis) and works fine without any particular configuration. Noting the lack of styling on your example page - before we go any further - have you got nginx configured properly? See Nginx (it being in a container is irrelevant).

Failing that, you're going to have to give us a detailed description of your setup.

Bear in mind that there's an "official" docker-compose script for developers here, https://github.com/moodlehq/moodle-docker. I found it way too complicated for my needs, so created my own but you might find it useful.
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Hi Howard and all

Talking of setting up Moodle in Docker, from the multiple ways of doing it, is there a tutorial on setting up a Moodle server on Docker for _production_? Even the "official" one at https://github.com/moodlehq/moodle-docker says, "This repository contains Docker configuration aimed at Moodle developers and testers to easily deploy a testing environment for Moodle."
Visvanath Ratnaweera-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
The problem is that you are, in effect, writing your own, dreaded, one-click installer for Moodle. So they question becomes, "Docker environment to do what?".

My approach was to look at tutorials for building a basic LAMP stack in Docker and extrapolating from there.
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Marcus Green -
Core developers зураг Particularly helpful Moodlers зураг Plugin developers зураг Testers зураг
" I found it way too complicated for my needs, so created my own but you might find it useful."
I too found it rather complicated ...
Marcus Green-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
It was my "right... I'm going to learn Docker moment" том инээмсэглэл
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Hi Marcus, hi Howard

What you both say is that your Moodle in Docker are for testing and development, not for production? So, I am eager to get a recipe (templates) from others on how to create a Docker environment to _run_ Moodle in production. I know, "Why don't you try?" I'm cautious since not long ago I was dragged in to a Moodle in Docker environment that just vapourized during some sort of an upgrade. Don't ask me for details, I never had access to that platform, not before, not after.
Visvanath Ratnaweera-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
Indeed - I have no requirement to do that. I have no idea how to deploy Docker in large / high-availability environments. I'm assuming that's where things like Kubernetes come into play - but that's far outside of my experience.
Marcus Green-н хариуд

Re: Moodle in docker environent

дэргэд Rick Jerz -
Particularly helpful Moodlers зураг Testers зураг
At this year's MountainMoot, I attended a session titled "Docker & Moodle: Setting Up Your Local Learning Playground," provided by Alan McCoy from NCSU. Alan did a great job, but because I am always slow at things, I had problems getting Docker to work on my Mac. At the Moot, I persisted by catching Alan at different times during the Moot, asking questions, and trying things. Eventually, I succeeded in getting Docker working.

As with many of these experimental environments, sometimes it is hard to see their advantages. I have used XAMPP, MAMP, Moodlebox, and experimental installs on my servers. They each seem to offer interesting features. My "impression" of Docker is that it may provide more backend server-type configurations for testing. For my simple-minded approach to experimenting, MAMP on my Mac is where I am at right now. Docker seemed interesting to me, but I wasn't convinced to continue with it over my MAMP environment.

I am unsure if Alan provides any resources on a website. And I am unsure if the MountainMoot folks would allow guest access to his resources. The session looks like my screenshot, below.

Хавсралт Docker at MountainMoot.jpg
Rick Jerz-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
My sales pitch for Docker. This may in no way apply to you.

I typically, have (say) the current version of Moodle, the future version and possibly other versions all running side by side on the same box. Quite possibly with different versions and configurations of server software. If someone says, "what happens if we try PHP 8.3?" I can change the config in the php container (often literally just changing the version number) and rebuild the thing. 30 seconds and it's running. I can also share my config files in GitHub and somebody else (or me on a different PC/Mac) is guaranteed to have the identical setup. 

You may not care about any of this - and, if you don't, it's just a layer of complexity that you don't need.
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Rick Jerz -
Particularly helpful Moodlers зураг Testers зураг
Yes, you are correct, Howard. I don't have to do that kind of experimenting in my case. You are the type of system administrator who must get into those questions, and Docker is better at exploring them. My needs are much simpler. I have a small VPS, and it is what it is.

I do, however, appreciate how you have worked with all of these alternatives and have become a great resource to our community. Thanks.
Rick Jerz-н хариуд

Re: Moodle in docker environent

дэргэд Marcus Green -
Core developers зураг Particularly helpful Moodlers зураг Plugin developers зураг Testers зураг
Docker and VSCode/Codium are probably the two most useful tools I have discovered in the last few years that make developing and testing Moodle easier. If you use docker then getting used to docker compose is very useful. To give an example I have been working extensively with the STACK (maths) question type recently and it requires a thing called Goemaxima (as the back end). I have never run it in any other way than via Docker, and doing it with docker makes updating trivial. Also docker took away the extensive misery I experienced with behat testing over many years. Plus VSCode/Codium have excellent Docker integration.

However people tend not to run production sites under docker.
Rick Jerz-н хариуд

Re: Moodle in docker environent

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг

Rick

My web search for the session you mentioned brought only its announcement:

https://www.mountainmoot.com/sessions.html

But I think it is not the one we are looking for in this thread. "Playground [..] where you can experiment to your heart's content" implies that it is not for production.

My search on YouTube brought this session though:

Self-built Moodle Docker testing environments | MoodleMoot Global 2022

The "self-built" part leaves a production usage open.

Visvanath Ratnaweera-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
May I suggest.... it's not (to me) a case of "how can I run Moodle in containers for production?"... it's "what problem do I have that running in containers will solve?".
 
All these things are another layer of complexity and settings to get wrong. 
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Rick Jerz -
Particularly helpful Moodlers зураг Testers зураг
Yep, Howard, there are always two parts, as you depict. #1) Can I get the software to run in my preferred environment? #2) Once the software is installed, how do I use it?

I struggled a lot with #1. I finally got Docker installed and running, but even though this was last month, I cannot remember my problem. I do remember showing Alan that my Docker was working, and I explained to him the problem I had fixed. Then, I went on and installed Moodle. Got it up and running, with only a few problems along the way. As I explored, I wondered where Moodle was located, where the database was, and where moodledata was. Alan helped me figure these things out, but it was not obvious to me.

So, I sit here today with a version of Docker and Moodle. Since I have been running my experimental Moodle in MAMP, I can't yet figure out the problems that "running (moodle) in a container" will solve for me. So, it's just another interesting experimental environment.
Howard Miller-н хариуд

Ri: Re: Moodle in docker environent

дэргэд Sergio Rabellino -
Particularly helpful Moodlers зураг Plugin developers зураг

Q: what problem do I have that running in containers will solve?

My A:

Pro1: containers abstract from the VM or bare-metal operating system/libraries, so creating a container image (choosing i.e. a specific os-release) let you having different OSes between system and the Moodle Container. You can i.e. run your system with Ubuntu 20.04 and Moodle on Ubuntu 22.04 or completely another OS, eg RedHat derivatives). The operating system isolation could help in managing different libraries between host and container or having a container for production and another one for developing/testing on the same machine, without the need to manage the coexistence on the same system.

Pro2: Containers can be run/moved seamlessly between hosts (obviously you should have the same volumes available everywhere e.g. moodledata and config.php) without the need of reinstall all the packages/dependencies.

Pro3: Containers were thought for "micro services" so you can separate haproxy, web server (nginx/apache), redis, mysql/postgres into different containers, maybe on other machines without changing the configuration of underlying hosts. You can have many releases of each application running in their isolated context: it's up to you to choose what builds up your production and what it's still "in progress".

Pro4: Containers can be profiled for performance tuning and replicated simply starting a new instance.

Pro5: Containers recipe can be shared (Dockerfile) so you could build them by yourself, or adopt/adapt to tailor your needs.

Cons1: Changing a single bit inside a container imposes a redeploy of the container, so you'll have a disruption time. What it's inside the container and what is not (external volume mount) should be carefully selected.

Cons2: The network layer should be based on internal networks for security concerns, so the use of a reverse proxy (haproxy i.e.) should be hardly considered.

HTH.

Sergio Rabellino-н хариуд

Re: Ri: Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
I'm much the same, except I'd be interested if you could expand on "The network layer should be based on internal networks for security concerns, so the use of a reverse proxy (haproxy i.e.) should be hardly considered" a bit more?
Howard Miller-н хариуд

Ri: Re: Ri: Re: Moodle in docker environent

дэргэд Sergio Rabellino -
Particularly helpful Moodlers зураг Plugin developers зураг
You're welcome!
A container can catch up the host networking (that should own a public IP interface) or use an internal network, one of the classical 192.168.x.x or 172.16.x.x, for connecting all the containers between them (eg. your nginx container to the MySQL container). I believe that should be more secure having all the containers running on internal network IP, so listening sockets are outside of the scope of internet. Then you should use an haproxy (which can be containerized itself or not) to serve your Moodle website.

Probably my English it's not better enough to be precise and concise инээмсэглэл
This is lean or mean what also kubernets do when you publish a pod on internet.
Sergio Rabellino-н хариуд

Re: Ri: Re: Ri: Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
Ahh... ok. I see what you mean now.

Yeh - that's definitely a downside. I've ended up with five nginx instances all on different ports with a reverse proxy in front. It might just be me, but reverse proxies are one of those things that I always find confusing to set up.
Howard Miller-н хариуд

Re: Ri: Re: Ri: Re: Moodle in docker environent

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
From a video I saw the beauty of it is to have x number of instances providing "micro services" in a private network and with the help of Traefik collectively serve one single port of the host.
нүд ирмэх
Visvanath Ratnaweera-н хариуд

Ri: Re: Ri: Re: Ri: Re: Moodle in docker environent

дэргэд Sergio Rabellino -
Particularly helpful Moodlers зураг Plugin developers зураг
Yes, traefik should do the same work as haproxy, but I prefer the latter probably because I'm an old man. I enjoyed Haproxy and it saved me from DDOS many times, so for me, it's a mandatory element in a web service pipeline - or buy some commercial service like cl...re (I don't want to promote them). We use a haproxy in front of our Moodle platforms since 2008.
Sergio Rabellino-н хариуд

Re: Ri: Re: Ri: Re: Ri: Re: Moodle in docker environent

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Sergio, thanks for bringing up HAProxy, sounds more familiar than Traefik.
нүд ирмэх
 
Just to be sure, does your production Moodle runs on the setup you described?
Visvanath Ratnaweera-н хариуд

Ri: Re: Ri: Re: Ri: Re: Ri: Re: Moodle in docker environent

дэргэд Sergio Rabellino -
Particularly helpful Moodlers зураг Plugin developers зураг

My production platforms are based on Linux HA for historical reasons (pcs/corosync/pacemaker), so the backends work on bare metal nodes with haproxy as a main frontend. nodes are completely dedicated to Moodle, so there is no need to isolate things that in turn would lead to dockerize them. Anyway if you ask to me to dockerize Moodle starting from actual experience, probably it's a one day work.

Just as an example, on my laptop I have Rocky 9, but if a tool needs e.g. Ubuntu, it's a matter of writing a single line Dockerfilelike below

FROM ubuntu

and I have an ubuntu (latest) shell in 10 seconds. Only for this I believe that having docker it's useful.

Howard Miller-н хариуд

Re: Moodle in docker environent > for production

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Another set of "Howard spoke" type of comments.
инээмсэглэл

> it's not (to me) a case of "how can I run Moodle in containers for production?"... it's "what problem do I have that running in containers will solve?"

Well, that disqualifies me. Not that I don't have problems with my big iron approach to production Moodle servers, but from what I read so far, none of them will be solved by changing to Docker.

Still, I want to give those who propagate Docker a fair chance, to present their case "Why Docker for production Moodle?"

> All these things are another layer of complexity and settings to get wrong.

That could be the reason why so many Moodle in Docker solutions say, they are for testing and development. But, as I said above, am still waiting for proposals. What I don't know is whether A new "Large scale Moodle deployment" support group knows that we are looking for Docker solutions for (large scale) Moodle servers. I'm not on Telegram, could somebody post a link to this discussion in their Telegram channel?
 
P.S. I appended the subject line with "for production". There are many sub-threads in this discussion.
Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
 
Yeah, I'm keen to know the tutorial you used to set this Moodle on Docker.
 
P.S. Generally this kind of system administration questions are not directly for the Moodle developers. I would say Installing and upgrading help is the right place.
Visvanath Ratnaweera-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Steve Pelham -

 VOW!

Thanks the two of you for your targeted help!

https://github.com/moodlehq/moodle-docker worked rightaway. I can switch versions very easily via the shell variables. That will help me for the upgrading process.

 However with regard to the final production server the goal remains, to have an nginx as webserver in combination with php-fpm. So you think it is ok to run nginx with php-fpm in the same docker-container ? Is there nginx solution provided by Moodle ?
 
So I verified the nginx.conf (i.e. /etc/nginx/conf.d/default.conf in the php-fpm-container) with recommended conf of moodle on https://docs.moodle.org/404/en/Nginx

Here is my nginx.conf:

nginx
It differs to my conf because I want to present the site on localhost:8080. So I need to take care of the server port 8080. The rest is more or less the same as by moodle recomended. The point is that I say 

  fastcgi_pass php:9000
  
  instead of 

   fastcgi_pass 127.0.0.1:9000

because I wanted a different docker container to take care of the  php-fpm-service.

When I open "http://localhost:8080/user/editadvanced.php?id=2" with that conf i get the following output in the network tab of my console.

console


Docker conf looks like:

1.) Dockerfile

dockerfile

2.) docker-compose.yml

dockercompose

If you have a hint or further information for me I would be greatful !

Best,

Steve

Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
If it helps, here is the Docker setup I use for dev - https://github.com/thepurpleblob/DockerMoodle

It has nginx and php-fpm in separate containers. Actually two - one for the web and one for cron.

Please note!! This was not intended to be shared, and the notes are mostly for me for when I forgot what I did. So please tread carefully.
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Steve Pelham -

Hi Howard,

thanks for the link to your docker ... that looks very promising!

After having installed everything, it does not work ...

What should be the exact link ?

According to the config.php it must be:

http://localhost/

But for that link I get "the webpage is not available" in the browser.

http://localhost:8082/
yields
"403 Forbidden"

http://localhost:8082/moodle/

yields  this one in the browser:

asdrt

Can you help me one more time ?

Thanks a lot!

Best,
Steve

Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
The config file may not be correct. These are the relevant bits of my (working) config.php...

$CFG->dbtype = 'mariadb'; // 'pgsql', 'mariadb', 'mysqli', 'auroramysql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native'; // 'native' only at the moment
$CFG->dbhost = 'mysql'; // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname = 'moodle44'; // database name, eg moodle
$CFG->dbuser = 'root'; // your database username
$CFG->dbpass = 'purple'; // your database password
$CFG->prefix = 'mdl_'; // prefix to use for all table names
 
 
$CFG->dataroot  = '/app/moodledata';
 
Before anybody says anything - this is a completely local install in a test site, so the passwords are not intended to protect anything "real".
 
The ubuntu2.local is the hostname of the server on my local network so that I can access Moodle from other machines. I can't see why 'localhost' wouldn't work if you don't need that.
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Steve Pelham -
Hi Howard,

thanks for your patience !

I just changed the database name to 'moodle44' and the set

$CFG->wwwroot = 'http://localhost:8082/moodle';

and now it works ...

sry for the stupid questions .... however, there will be more questions ...

Best,
Steve
Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Steve Pelham -

Hi Howard,

I'd like to come back to you with a question.

The setup in your example works for moodle 4.1.
And I installed it...

That "setup" I need for moodle 3.9...
So I changed settings to moodle 3.9, which requires e.g. some ancient PHP 7.3 for instance.
Even that worked.
However, when I open "http://localhost:8082/moodle" I get no install routine like for the first
time when I installed  moodle 4.1

In the Browser I get this message:

werwert
So what I did was ... I created a separate folder and cloned  https://github.com/thepurpleblob/DockerMoodle
one more time and followed the instruction of the readme. I would have submitted, that it would create
a separate instance alongside the old one (i.e. moodle 4.1). 

Can you get me started how make a fresh install ? What must be changed in the config ? How to purge the old
one mayne ?

Thanks a lot!

Best,

Steve

Steve Pelham-н хариуд

Re: Moodle in docker environent > thepurpleblob/DockerMoodle

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг

Hi 

This sub-thread is about the https://github.com/thepurpleblob/DockerMoodle, the one Howard provided, right? Were you able to get your own Docker setup in the original post running which ended with this post?

Visvanath Ratnaweera-н хариуд

Re: Moodle in docker environent > thepurpleblob/DockerMoodle

дэргэд Steve Pelham -
Hi Visvanath,

no I was not able to implement my initial situation (shown above) with the solution of https://github.com/thepurpleblob/DockerMoodle. I don't know how to implement a solution for Moodle 3.9 ( with php 7.3). Moodle 4.1 with PHP 8 is of course worling.

Best,

Steve
Steve Pelham-н хариуд

Re: Moodle in docker environent > thepurpleblob/DockerMoodle

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
I got Moodle 1.9 working in a setup based on those docker compose files a few months ago. For fun / a talk I was giving. You can *just* get old enough versions of PHP and MySQL for Docker.
Хавсралт Screenshot 2024-08-27 at 10.22.14.png
Howard Miller-н хариуд

Re: Moodle in docker environent > thepurpleblob/DockerMoodle

дэргэд Marcus Green -
Core developers зураг Particularly helpful Moodlers зураг Plugin developers зураг Testers зураг
Got a docker-compose yml file for that?


Marcus Green-н хариуд

Re: Moodle in docker environent > thepurpleblob/DockerMoodle

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
This might give you a start. As ever it was all bodged together in a rush so please don't judge me инээмсэглэл
 
I also got 1.4 working, but I had to modify the Moodle code to get it to run and I can't remember what I did. 
 
Docker compose...

version: '3'
services:
  web:
    build:
      context: .
      dockerfile: PHP.Dockerfile
    restart: unless-stopped
    ports:
      - "8081:80"
    volumes:
      - ./webroot:/var/www/html
      - ./moodledata:/var/www/moodledata
      - ./php.ini-development:/usr/local/etc/php/php.ini
  db:
    image: mysql:5.7
    volumes:
      - ./my/custom:/etc/mysql/conf.d
      - mysqldata:/var/lib/mysql
    ports:
      - "3307:3306"
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: "purple"
      MYSQL_USER: moodleuser
      MYSQL_PASSWORD: "moodlepass"
      MYSQL_DATABASE: moodle19
volumes:
  mysqldata:
~    
      
PHP.Dockerfile:
 

FROM php:5.6-apache-jessie

ADD root/ /
# Fix the original permissions of /tmp, the PHP default upload tmp dir.
RUN chmod 777 /tmp && chmod +t /tmp
# Remove jessie-updates from sources (https://lists.debian.org/debian-devel-announce/2019/03/msg00006.html)
RUN sed -i '/jessie-updates/d' /etc/apt/sources.list
RUN sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list
RUN sed -i 's|security.debian.org|archive.debian.org|g' /etc/apt/sources.list
RUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com 7638D0442B90D010
# Setup the required extensions.
RUN /tmp/setup/php-extensions.sh
RUN /tmp/setup/oci8-extension.sh

RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \
    mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \
    mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \
    mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps

 
Visvanath Ratnaweera-н хариуд

Re: Moodle in docker environent > thepurpleblob/DockerMoodle

дэргэд Steve Pelham -
Hi again,

everthing 's working ...
First I copied folders ... so the crucial folders had the same name. Now I changed and said:
docker compose -p dockermoodle down --volumes

yep beginner mistakes ...

Best,

Steve
Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Doulos Xavier -

Interesting, so are you running it within your private network or host? That looks little strange, or probably I am missing something. 

Doulos Xavier-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
I'm not sure who you are asking... but I'm running it on a private network for development / testing. Our production site is completely different.

I also run the same containers on a MacPro laptop when I'm out and about. That (just to confuse the issue) runs the containers inside an Ubuntu Server VM. The reason for this is that while Docker does run on Macos, it's rubbish.
Howard Miller-н хариуд

Re: Linux on MacPro laptop [OT]

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг

[OT]

I know, I'm going to ignite another Mac vs Linux war. But it is such a huge coincidence, couldn't keep silent. I touch a Mac device maybe once every couple of years. But as I read you run Docker containers inside an Ubuntu Linux VM inside a MacPro, I was working on a MacBook Pro (and writing this post now):

The hardware is stunning. The screen big, bright and clear. The speakers, flat to the left and right of the keyboard, the sound is of a higher quality than my external Bluetooth speakers which take the volume of a shoe box. The battery still can power 10 minutes of YouTube!

The surprise, according to https://support.apple.com/en-us/108052 "MacBookPro5,1 1.0" is from the late 2008!

I don't know when OS X El Capitan died, but the ship sails smoothly under the current Linux Mint 21.3 Cinnamon "Wilmar". It runs YouTube videos full-screen without any flicker. I bet, I need to install the Docker daemon and Docker Compose, it'll run Docker native.

For somebody who cares about energy efficient servers, this is vicious - artificially killing brilliant hardware to maximize profit thereby ignoring the damage to the environment.

OK, can't change Apple nor its disciples. If anybody wants to test this machine respond quickly. It is not mine. I just serviced it and gave it a second life under Linux. It'll will be sent to a new place to enjoy the second life.

Visvanath Ratnaweera-н хариуд

Re: Linux on MacPro laptop [OT]

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
MacOS definitely runs Docker natively but it doesn't have the kernel file modules that Docker needs. So Docker has to run an abstraction. Result - Moodle has 20 second+ page load times.

I need the Mac for other things (as well as it looking pretty) but the Ubuntu VM solves the Docker issue. In fact, it's blisteringly quick.
 
I've got about 5 of them but the M1 is the one the day-job handed out with all the VPN stuff. So, as ever, it's making what I have work. 
 
I'm typing now on a ten year old 27" iMac natively running the latest Linux Mint. Absolutely perfectly. So, yeh нүд ирмэх
Howard Miller-н хариуд

Re: Linux on MacPro laptop [OT]

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Yeah, I have heard from a colleague about the issues Docker has on MacOS native. Why don't you build your Docker environment on the iMac running Linux natively? Maybe you have Docker on more than one device. Still, I can't imagine how you drive on five wheels.
инээмсэглэл

I can imagine the iMac, 27"(!), to be a great Linux desktop. BTW, coincidentally Linux Mint. Although my personal desktop has been MX Linux since a long time, for this project, reclaiming old laptops for students, I chose Linux Mint. I think, it is a good middle path between beginners and experienced Linuxers.
Visvanath Ratnaweera-н хариуд

Re: Linux on MacPro laptop [OT]

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
I have multiple development environments because I work in different locations throughout the week.

I got hold of a bunch of old 27" iMacs. A couple of them didn't work and have been converted into very nice external monitors. I got cheap monitor drivers for them from AliExpress. Works perfectly.
Howard Miller-н хариуд

Re: Linux on MacPro laptop [OT]

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
I know, we are way off-topic. But couldn't resist coming back because of the coincidence. You mentioned iMacs, just yesterday a colleague pulled an iMac for a Linux experiment. Again an impressive screen I must say. I write on it as it is churning in the background updating itself from Linux Mint 20 to 21. Amazing, even in "Mid 2011" (iMac12,1 1.0) it had an Intel i5, albeit 2nd generation.
 
 
 
Edit. In the meantime it says:
update-initramfs: Generating /boot/initrd.img-5.15.0-119-generic
Check succeeded:  Final phase
Upgrade successful! You can now close this terminal and reboot your computer.
Visvanath Ratnaweera-н хариуд

Re: Linux on MacPro laptop [OT]

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Oh man, was I a blockhead! We often "agree to disagree" on the question "Mac or Linux" but the answer was for all the world to see, it is not "Mac OR Linux" but "Mac AND Linux", or to be more precise, "Why you should run Linux on your Mac".
 
The results in this [OT] thread convinced me. If you need a "video" to believe, search for that phrase in your infamous Tube, if you are not shy, or get FreeTube.
нүд ирмэх
Doulos Xavier-н хариуд

Re: Moodle in docker environent

дэргэд Steve Pelham -
Hi Benoit,

our situation now is that we have a monolithic solution for our productive environment, i.e. one root server that takes care for everything. The aim is to have different docker containers for the services ...

What is more we need to update. So I try to set up a docker environment locally, in order to make the updates on a local machine.

If you have experiences concerned with docker environment for a productive moodle intances ... please let know инээмсэглэл

Best,
Steve
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Steve Pelham -

Hi Howard,

once again  your set up help me very much ...

however, wasn't able to get STACK / Maxima running.  I think I can do the settings from the moodle site here:

<moodle-host>/admin/settings.php?section=qtypesettingstack

So the url to the Maxima Pool would be 

127.0.0.1:8765:8080 ?

Do I have to create a STACK image in the docker ?

So in short ... Do you have small how to here ?

Best Thanks!

Steve

Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Marcus Green -
Core developers зураг Particularly helpful Moodlers зураг Plugin developers зураг Testers зураг
docker-compose goemaxima.yml up -d
with goemaxima.xml being
version: "3.3"
services:
  maxima:
    image: mathinstitut/goemaxima:${STACKMAXIMA_VERSION:-2024072400}-latest
    ports:
      - 0.0.0.0:8080:8080
    tmpfs:
      - "/tmp"
    restart: unless-stopped
    cap_add:
      - SETGID
      - SETUID
    cap_drop:
      - ALL
    read_only: true
~                    
Marcus Green-н хариуд

Re: Moodle in docker environent

дэргэд Steve Pelham -

Hi Marcus,

... just installed maxima with the docker image from "https://hub.docker.com/r/mathinstitut/goemaxima".

I have a docker-compose.yml -file like you and the Maxima docker works. So the url

http://localhost:8080/goemaxima?health=1

  delivers:

wertwe

So that looks good to me ...

But I can't reach it via Moodle.  The healthscript of our Moodle instance says:

sfsf

My maxima config in Moodle is:

rtzretze

Can somebody help me to get it running?

 any hints ? 

Thanks in advance for your help.

Best,

Steve

Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
Yeh - I have STACK in my GitHub but I didn't get it working. If you do, perhaps send me a pull request инээмсэглэл
Howard Miller-н хариуд

Re: Moodle in docker environent

дэргэд Marcus Green -
Core developers зураг Particularly helpful Moodlers зураг Plugin developers зураг Testers зураг
I am at Peek STACK at the moment, I will see what I can do.
Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Ken Task -
Particularly helpful Moodlers зураг

Pardon 2 cents worth ...

Noticed in your screen shots you acquire the moodle code via git and then remove the hidden .git directory ... which means you loose the ability to acquire point releases - maybe even 0 day flaws (happened only once in many years, but still ...)

You also loose the ability to upgrade the site as long as server has compat versions of PHP + extensions and DB version in place without the need of a new docker.

https://moodledev.io/general/releases

Yes, Docker gets AMP stack and a moodle setup quickly ... but doesn't that kinda limit you to above the water line with the moodle?

Often wondered ... so I'll ask a non-docker user stupid question ... how does that setup handle updates/upgrades to PHP/DB server/Web server?

There are things that need to be setup outside of moodle once it's up and running ... cron job.  Maybe you could include in your docker a bash shell script to do a site backup?

For that matter, if one left .git, 2 more scripts ... one to update code for a point release ... and another to upgrade site when a desired higher version is released.

'SoS', Ken

Ken Task-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
It's a slight over-simplification but - here's were Docker wins - to obtain a new version of Moodle and update all the requirements, copy the config files, change the version numbers and rebuild. In fact, you can have multiple versions of everything running at once. To me, that's what makes it worth the trouble.
Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Hi

You are talking of two things, a) what is wrong with my Moodle in Docker? b) how should one run Moodle in Docker for production? Two topics are already far from the ideal one-topic-one-discussion style forum discussions here. And to which people contribute their solutions for _testing and development_ making it worse.

Trying to focus on your first topic, "a) what is wrong with my Moodle in Docker?", I see that your Nginx location is just /.php$ whereas Nginx talks of [^/]\.php(/|$) and ^(.+\.php)(.*)$. I never had to use the latter, the former always worked.

On your second topic, "b) how should one run Moodle in Docker for production?" I am too waiting for a convincing answer.
Visvanath Ratnaweera-н хариуд

Re: Moodle in docker environent

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
I'm yet to encounter a large-scale, production version of Moodle running in containers. It doesn't mean it's not out there but people who are into that sort of thing tend not to share their experiences here.
 
However, a solid first step is surely getting it to work at all?
Howard Miller-н хариуд

Re: How should one run Moodle in Docker for production?

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
On the question b) How should one run Moodle in Docker for production?

> I'm yet to encounter a large-scale, production version of Moodle running in containers.

It says something. Still I want to give the Docker users a chance without prejudice.

> It doesn't mean it's not out there but people who are into that sort of thing tend not to share their experiences here.

Well, that means Docker is not ripe for me. a) I always say, an IT product is as good as its support. If there is a divide, experts not ready to share and beginners who are helpless, I don't want to go there. b) The transparency. I don't want to be a voodoo doctor.
нүд ирмэх

> However, a solid first step is surely getting it to work at all?

Do you mean _I_ should start exploring? Why should I? I am not unhappy with the (openly) available technology.
Visvanath Ratnaweera-н хариуд

Ri: Re: How should one run Moodle in Docker for production?

дэргэд Sergio Rabellino -
Particularly helpful Moodlers зураг Plugin developers зураг

We probably need to distinguish between container technology and Docker, a product for running containers...

Moodle.org is running on Kubernetes, which in turn uses containers (pods are similar to docker-compose), so reading this post, we are viewing a Moodle installation in production running on containers, or I'm wrong?

So, Docker was the first usable tool for managing containers and its effectiveness it's not in doubt in my direct experience when you need to create a service that abstracts from the host operating system without losing performance. Is it needed for Moodle? Surely no! Can be useful? Yes, but it depends on specific requirements/environment that should be evaluated. It's not a silver bullet, it's technology.

Sergio Rabellino-н хариуд

Re: Ri: Re: How should one run Moodle in Docker for production?

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Hi Sergio

Thanks for your insightful post.

Yeah, we need to be aware of the difference between containers in general and Docker as one of them. Note that this discussion is specifically about Docker. See the original post and the subject line.
 
Your example of moodle.org: If it is on Kubernetes, we can say it uses some kind of containers, not necessarily Docker.
 
Since our main topic is Docker for _production_ Moodle, in your third para you mention some scenarios where Docker has definitive advantages, but none mentions Moodle for production.
 
Still, there must be people who use Moodle on Docker for production. I am hoping they will share us their experience with us. 
Visvanath Ratnaweera-н хариуд

Ri: Re: Ri: Re: How should one run Moodle in Docker for production?

дэргэд Sergio Rabellino -
Particularly helpful Moodlers зураг Plugin developers зураг

To be short, containers are containers... So K8s or Docker the pro/cons are almost the same. 

The big difference could be about the container orchestration capability and how can be layered complex and distributed services and how can be simple to manage the container demand on the concurrent users automatically or not (K8s should do it, Docker probably not).

The main problems in using containers are the external volumes to get storage persistence and how it's done. In K8s probably you'll have some networked volumes, while in docker you can pinpoint directly an SSD. Networking in K8s it's a bit more complex (as it should work on very complex applications), Docker it's simpler.

IMHO, all the other aspects stay the same: when you need to upgrade some libraries, you need to rebuild the container image and redeploy, like in a normal bare-os.

Visvanath Ratnaweera-н хариуд

Re: How should one run Moodle in Docker for production?

дэргэд Howard Miller -
Core developers зураг Documentation writers зураг Particularly helpful Moodlers зураг Peer reviewers зураг Plugin developers зураг
I don't mind if you explore this or not. I'm not a Docker (or containers at all) evangelist. What I am a proponent of is "KISS" and don't just use fancy new technology for the sake of it. It's all more "stuff" to learn and to go wrong.

What is does do, is to solve a particular situation I have. I'm not directly involved in running Moodle in production - they pay somebody else to do that нүд ирмэх
Steve Pelham-н хариуд

Re: Moodle in docker environent

дэргэд Mark Berthelemy -
Hi,
I've encountered similar problems using Devilbox (a pre-configured set of Docker environments - PHP, Apache, MySQL).
I've started a new thread at https://moodle.org/mod/forum/discuss.php?d=461349 as it seems your issue was sorted by tweaking the nginx configuration, and I'm using Apache.
Thanks,
Mark
Mark Berthelemy-н хариуд

Re: Moodle in docker environent

дэргэд Visvanath Ratnaweera -
Particularly helpful Moodlers зураг Translators зураг
Thanks for bringing up Devilbox http://devilbox.org/, a reincarnation of Linux appliances in the old days in much lighter form.
нүд ирмэх
 
If I may add a platform to run all these, enter Proxmox https://distrowatch.com/table.php?distribution=proxmox. It has built a powerful GUI, a "panel", around Debian GNU/Linux building a full "data center" to run all kinds, VMs on KVM, Linux containers (LXC) and of course Docker. Stacking them if you want, an LXC on VM, Docker on LXC!