I want to create docker-compose setup with 2 containers.
- A MariaDB Container
- A Moodle container based on bitnami/moodle:latest
These containers should be used for testing custom PHP plugins for Moodle WebServices. To do so I have to copy the newest version of my plugin code to the location /bitnami/moodle/local/local_custom_api/
I did this in the Dockerfile
FROM bitnami/moodle:latest
COPY ./local_custom_api/ /bitnami/moodle/local/local_custom_api/
And then I created the following docker-compose.yml
version: '3.8'
services:
mariadb:
image: mariadb
volumes:
- D:\Docker\Moodle\Database:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=moodle
- MYSQL_ROOT_USER=root
- MYSQL_DATABASE=moodle
moodle:
build: .
ports:
- 8080:8080
- 8443:8443
environment:
- MOODLE_DATABASE_HOST=mariadb
- MOODLE_DATABASE_USER=root
- MOODLE_DATABASE_PASSWORD=moodle
- MOODLE_DATABASE_NAME=moodle
volumes:
- D:\Docker\Moodle\Moodle:/bitnami/moodle
- D:\Docker\Moodle\MoodleData:/bitnami/moodledata
depends_on:
- mariadb
links:
- mariadb:mariadb
This works fine and both containers are created and the moodle install script completes successfully but the copy cmd in the Dockerfile does not work. The files do not show up in the specified volume.
After some research, it seems that I have to use named volumes to make the copy cmd work (don’t really know why). So I created named volumes but now the moodle install process cannot find a file although I just changed the host path of the volume
Here is the new docker-compose.yml
version: '3.8'
services:
mariadb:
image: mariadb
volumes:
- moodle_db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=moodle
- MYSQL_ROOT_USER=root
- MYSQL_DATABASE=moodle
moodle:
build: .
ports:
- 8080:8080
- 8443:8443
environment:
- MOODLE_DATABASE_HOST=mariadb
- MOODLE_DATABASE_USER=root
- MOODLE_DATABASE_PASSWORD=moodle
- MOODLE_DATABASE_NAME=moodle
volumes:
- moodle_app:/bitnami/moodle
- moodle_data:/bitnami/moodledata
depends_on:
- mariadb
links:
- mariadb:mariadb
volumes:
moodle_db:
driver: local
driver_opts:
type: none
device: "D:\Docker\Moodle\Database"
o: bind
name: moodle_db
moodle_app:
driver: local
driver_opts:
type: none
device: "D:\Docker\Moodle\Moodle"
o: bind
name: moodle_app
moodle_data:
driver: local
driver_opts:
type: none
device: "D:\Docker\Moodle\MoodleData"
o: bind
name: moodle_data
This is the output. The install always crashes and the only files in the moodle_app volume are the plugin files that were copied successfully:
moodle-test-moodle-1 | moodle 16:04:14.05
moodle-test-moodle-1 | moodle 16:04:14.05 Welcome to the Bitnami moodle container
moodle-test-moodle-1 | moodle 16:04:14.05 Subscribe to project updates by watching https://github.com/bitnami/containers
moodle-test-moodle-1 | moodle 16:04:14.05 Submit issues and feature requests at https://github.com/bitnami/containers/issues
moodle-test-moodle-1 | moodle 16:04:14.05
moodle-test-moodle-1 | moodle 16:04:14.05 INFO ==> ** Starting Moodle setup **
moodle-test-moodle-1 | realpath: /bitnami/apache/conf: No such file or directory
moodle-test-moodle-1 | moodle 16:04:14.08 INFO ==> Configuring Apache ServerTokens directive
moodle-test-moodle-1 | moodle 16:04:14.10 INFO ==> Configuring PHP options
moodle-test-moodle-1 | moodle 16:04:14.10 INFO ==> Setting PHP expose_php option
moodle-test-moodle-1 | moodle 16:04:14.12 INFO ==> Validating settings in MYSQL_CLIENT_* env vars
moodle-test-moodle-1 | moodle 16:04:14.13 INFO ==> Validating settings in POSTGRESQL_CLIENT_* env vars
moodle-test-moodle-1 | moodle 16:04:14.19 INFO ==> Restoring persisted Moodle installation
moodle-test-moodle-1 | moodle 16:04:16.25 INFO ==> Trying to connect to the database server
moodle-test-moodle-1 | grep: /opt/bitnami/moodle/config.php: No such file or directory
moodle-test-moodle-1 exited with code 2
How can the host location affect the internal functionality of the container?
2
Answers
The problem is, in the docker compose, you are bind mounting to the parent directory of the directory that has been copied in the docker file. The docker docs says: if a container directory is non-empty it is hidden behind the contents of a bind-mounted directory (i.e. you can’t initialize the host directory with a container files there in this way). Therefore your copy at
/bitnami/moodle/local/local_custom_api/
(in container) is hidden instead the directory is the same asD:DockerMoodleMoodle
… Similarly in the second
docker-compose.yml
The solution is really simple: put your plugins in the
D:DockerMoodleMoodlelocallocal_custom_api
. Also, you could instead of defining the docker file just use the default image in thedocker-compose.yml
:The copying in the docker file has another disadvantage during prototyping, it is just a copy and every time you change anything you must rebuild the container. On the other hand, volumes are "synchronize", they are the same directory visible both from the outside and the inside. So when you have new version of the plugin, you just restart the container.
Using (named) volumes is not necessary, see documentation for more informations what is the difference to the bind mounts (=using paths).
I had this same issue (also found this issue which was kind of annoying…).
I did this and it got resolved (taken from here):
/opt/bitnami/moodle/config.php: No such file or directory
The following error is raised if the moodle service has not completed the initial installation:
Please make sure if the initial installation has been completed.
If the error keeps happening, it would be better to clear the containers with the following commands:
and set it up again from the beginning.