Im trying to dockerize the moodle i've installed locally so it is easier for me to manage it when i elevate the moodle to "another level". In the future i will have several moodles so i need containers to be easier to manage them.
I've tried several aproches. I tried do create my onw image , using a dockerfile:
# Use an official PHP runtime as a parent image
FROM php:7.4-apache
# Set the working directory to /var/www/html
WORKDIR /var/www/html
# Copy the contents of your Moodle directory to the container
COPY . /var/www/html
# Install any additional dependencies or PHP extensions if needed
# For example:
# RUN docker-php-ext-install pdo_mysql
# Expose port 80 to the outside world
EXPOSE 80
# Start Apache when the container launches
CMD ["apache2-foreground"]
and a docker-compose.yml:
version: '3.8'
services:
moodle:
image: your-moodle-image-name
ports:
- "8080:80" # Adjust the port mapping as needed
but nothing works.
Also , i've tried to make just an docker-compose.yml file that runs both moodle and mariadb (but with bitnami/moodle image):
version: '2'
services:
mariadb:
image: mariadb
container_name: mariadb2
ports:
- 3306:3306
volumes:
- /srv/dev-disk-by-x/dckcnfg/moodle:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=passroot
- MYSQL_ROOT_USER=root
- MYSQL_DATABASE=moodle
- ALLOW_EMPTY_PASSWORD=yes
moodle:
image: bitnami/moodle
container_name: moodle2
ports:
- 8089:80
# - 8449:443
environment:
- MOODLE_DATABASE_HOST=localhost
- MOODLE_DATABASE_USER=user
- MOODLE_DATABASE_PASSWORD=pass
- MOODLE_DATABASE_NAME=moodle
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- /var/www/html/moodle:/opt/bitnami/moodle
- /var/www/moodledata:/opt/bitnami/moodledata
depends_on:
- mariadb
links:
- mariadb:mariadb
and it does not work. I get "trying to connect to db server" on the moodle logs. I guess it is beacause for me to deploy mariadb containar , i cannot have mariadb running for moodle outside the container , and then , i never get the container to speak with it to the outside.
Instead of rolling your own, there is a Moodle-HQ-maintained Docker project that might be worth looking into: https://github.com/moodlehq/moodle-docker
I personally have found success using the instructions to Use containers for manual testing, as that gives you an install you can interact with:
Most of the configuration can be changed by using environment variables; I gathered mine into an
.env.examplefile that I use for reference when spinning up a new environment: