Dockerfile Cookbook Recipes Attempt 2: moodle (Success!)

We get a functioning working moodle running inside a Docker Container that we build from near scratch!

Dockerfile Cookbook Recipes Attempt 2: moodle (Success!)

In the previous post we looked at installing moodle from source into its own image.  It failed as the standard php image did not include a mysqli connector.

Dockerfile Cookbook Recipes Attempt 1: moodle
In this guide we go over the first attempt at rolling your own moodle container.
  • We will make a Dockerfile that will add the necessary components to the php image - as currently none of the guides seem to work.
  • To solve this we stood up a local container and from inside it treated it as a normal system php installation.

Dockerfile: and the build / run

FROM php:7.0-apache
EXPOSE 80
docker build --tag php_local .
docker run -it --name php_local php_local sleep infinity
  • sleep infinity will keep a container from stopping for diagnostic purposes

Now one can attach to the running container:

docker exec -it php_local /bin/bash
apt-get update
apt-get install libpq-dev
docker-php-ext-install pgsql
  • This does seem to hold the commands that the above Dockerfile will require, and we can now amend it (after lots of trial and error to remove interaction)
FROM php:8.0-apache
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install libpq-dev -y
RUN docker-php-ext-install pgsql
EXPOSE 80

And then run it again:

docker run -it --name php_local php_local

We are now ready to try out our next moodle container:

docker run --name moodle -it -v /moodle/moodle:/var/www/html -p 8080:80  php_local:latest

Still an error:

One will need to adjust the Dockerfile to accomodate <quite> a bit of stuff here:

  • After about 30 iteration adjustment cycles to Dockerfile we come up with:
ROM php:8.3-apache
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install libpq-dev -y
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install libzip-dev -y
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install libpng-dev -y
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install libicu-dev -y
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install libxml2-dev -y

RUN docker-php-ext-install pgsql pdo pdo_mysql mysqli
RUN docker-php-ext-install zip
RUN docker-php-ext-install gd
RUN docker-php-ext-install intl
RUN docker-php-ext-configure intl
RUN docker-php-ext-enable intl
RUN docker-php-ext-install soap
RUN docker-php-ext-install exif
RUN mkdir -p /var/www/moodledata
RUN chown -R www-data:root /var/www/moodledata
RUN chown -R www-data:root /var/www
EXPOSE 80

We rebuild our container with:

docker build -t moodle_local .

It builds a LOT of stuff (makes probably a larger container) but looks like we finally might have good source build of a moodle image.

  • We use the tag moodle_local so it does not confuse with production builds of moodle.

To whit we can run this again:

docker run -it --name moodle_local -v /moodle/moodle:/var/www/html -p 8080:80 moodle_local:latest
  • It should be noted that yes one could compound these commands but when something breaks which one? Therefore it is good practice to add a bit to your Dockerfile as you go and build as you go.

Two errors remain:

  • A neat trick at this point is to simply migrate to your data directory (on the host outside the running container) and live add your php.ini file as in:
cd /moodle/moodle/
nano php.ini

And put inside it:

[opcache]
opcache.enable = 0
opcache.memory_consumption = 128
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 60

And then:

nano .htaccess

And put inside it:

php_value max_input_vars 5000

And simply hit your refresh in your browser (why was this not just added to the moodle in the first place ??)

And

Now it runs a giant installation script

From here we can finally set our admin access etc:

Result: Success!

  • A full fun configuration:
docker run -it -d --name moodle_local --restart unless-stopped -v /moodle/moodle:/var/www/html -p 8080:80 moodle_local:latest

It should be noted this is probably one of the best Dockerfile build guides out there on the internet in relation to Moodle!

Note: The success of this notebook also predicated on having a local mysql container stood up (here is a good short guide)

Dockerfile Cookbook Recipes Part 02: mysql
In this basic example we take a good strong look at building and rolling your own mysql containers with various options and a good guide on how it all works!

woot woot!

Linux Rocks Every Day