- docker-compose version 1.22.0
- macOS High Sierra
- docker version 18.06.1-ce
- Moodle 3.6.1
Moodle source code and environment requirement
Extra Tips: Clean docker container and image (Optional)
- I'm using the Moodle 3.6.1 source code to configure my development environment. Below are the environment requirement by the Moodle 3.6.1 application
- Below are the folder structure to build my containers
Parent
|
|-conf
| |-mysql
| | |-moodle.cnf (1)
| |-php
| | |-custom.php.ini (2)
|-src
| |-moodle (3)
| | |- (All the Moodle source code)
| |-scripts
| | |-moodle.sql (4)
|-Dockerfile (5)
|-docker-compose.yml (6)
- Refer to (5), I have a Dockerfile to configure both Apache, PHP and MySql in my container. I have added the command to create the "/var/www/moodledata" folder.
FROM php:7.0.33-apache
RUN docker-php-ext-install mysqli
RUN mkdir /var/www/moodledata
RUN chmod 777 -R /var/www/moodledata
- Refer to (6), it is my docker-compose.yml that I used to configure my application service.
version: "2"
services:
www:
build: .
ports:
- "8001:80"
volumes:
(6-1)--> - ./src/moodle:/var/www/html/
(6-2)--> - ./conf/php/custom.php.ini:/usr/local/etc/php/conf.d/custom.php.ini
links:
- db
networks:
- default
db:
image: mysql:5.7.13
ports:
- "3306:3306"
environment:
ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: moodle
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
(6-3)--> - ./src/scripts/dump:/docker-entrypoint-initdb.d
(6-4)--> - ./conf/mysql:/etc/mysql/conf.d
- persistent:/var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8000:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
- Refer to (6-1) in the docker-compose.yml, I have mounted the source code development folder to "./src/moodle" [Please refer to (3) at folder structure]. Please map your project directory from your favourite IDE to this folder. All the changes in the source code will be reflected in your development container immediately.
- Refer to (6-2) in the docker-compose.yml, all the configuration for your php.ini will be placed in custom.php.ini file. I have mounted the container's php configuration into "./conf/php/custom.php.ini" [Please refer to (2) at folder structure]. Please refer to the content of my custom.php.ini as shown below. I have included the opcache configuration which is required by Moodle installation here.
display_startup_errors=On
log_errors=On
zend_extension=opcache.so
[opcache]
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 60
; Required for Moodle
opcache.use_cwd = 1
opcache.validate_timestamps = 1
opcache.save_comments = 1
opcache.enable_file_override = 0
- Refer to (6-3) in the docker-compose.yml, I added my Moodle's DB dump (moodle.sql) at "./conf/mysql/" folder [Please refer to (4) at folder structure] on my local machine. I have mounted it to the container and all the SQL files place in this folder will be executed during the installation. Assumption: You have configured your Moodle with complete database.
- Refer to (6-4) in the docker-compose.yml, all the customization for your my.cnf will be placed in "./conf/mysql/" folder [Please refer to (1) at folder structure]. For Moodle installation, I have created moodle.cnf and placed all my configuration in this file. Please refer to the content of my moodle.cnf as shown below.
[client]
default-character-set = utf8mb4
[mysqld]
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
skip-character-set-client-handshake
[mysql]
default-character-set = utf8mb4
- Start the Moodle installation by executing command below. Browse to http://localhost:8001, your Moodle side is ready for use now.
#docker-compose up
$ docker stop $(docker ps -a -q)
$ docker rm $(docker ps -a -q)
$ docker rmi $(docker images -q)
$ docker volume rm $(docker volume ls -q)
Extra Tips: Explore the structure of the image in the container
- Run command below to check the container ID
$ docker ps
- Based on the container ID that we get from the previous command, run command below to remote into the container to explore the file structure
$docker exec -t -i [container id] /bin/bash
No comments:
Post a Comment