Added plugin already in dockerfile

Added plugin already in dockerfile

by roni bar -
Number of replies: 25

I am working with a model on the docker

I want to create a dockerfile in which I write the list of plugins that I use in the system.

So that when running the Docker image, the plugins I wrote for my model system will be loaded directly for me.

Average of ratings: -
In reply to roni bar

Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Roni, There are several approaches you could take here, using git, moosh, composer, or other methods. What do you have so far?

In reply to Mark Johnson

תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
First of all, thank you very much for the answer!
I am currently working with git
(I couldn't understand why this is significant to the question)
In reply to roni bar

Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Git offers several different methods of doing what you suggest. You could commit all of your plugin code to same repository as your core Moodle code, or you could define each plugin as a git submodule.

Then you can either clone the repository (and initialise the submodules if you're using them) on your build machine and use COPY in your dockerfile to copy the files into the container, or you could use RUN in your dockerfile to do the git commands within the build.

You could also keep the plugin repositories completely separate, and use RUN in your dockerfile to execute a series of git commands, cloning each plugin into the appropriate place. This would mean more code to maintain in the dockerfile than the options above, but less complex git setup.

Average of ratings:Useful (1)
In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -

Thank you very much for the answer

I want to download the plugins directly from their website without the need to download in advance and save in a certain place

That is, adding a line in the dockerfile to download the plugin from the plugins site

And in addition a row that installs the actual plugins on the moodle website

I would love to receive an example of a dockerfile that matches the requirement

(After all, on the plugins website there is an option to download manually, there must be an option to download from there also through a line of code).

In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That is possible, but you'd end up with quite a verbose dockerfile. I haven't seen or written any examples that do this, but you'd need something like:

RUN wget https://plugin/download/url/plugin.zip && \
 unzip -d /path/to/plugindir plugin.zip && \
 rm plugin.zip

For each plugin that you want to include. Actually installing the plugin to the moodle site isn't something that would happen in your dockerfile, that will happen when you run the install/upgrade from a running container.

In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
The above commands work fine for me anywhere in the container except into the volume.
Even when I tried to download to a certain place and then copy to the desired volume, the operation failed
I have a feeling that there is some basic routing to access the volume (maybe not, that's my feeling)
What is the difference between downloading/copying into a container and downloading into the volume in the container?
Can you give me a line of code (suitable for a Dockerfile) to download the plugin specifically into the volume
In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You may be misunderstanding how docker volumes work. Volumes are a persistent directories on the host that are mounted into a container at runtime. You cannot write into a volume from your dockerfile, at build time. I don't know exactly what will happen if your dockerfile does write to a location where you then mount a volume (if this is even possible), but my guess is that the container will see the contents of the volume, and not the files written at build time.

In the example I shared above in your dockerfile, docker will download plugin.zip to /, then unzip its contents into /path/to/plugindir, which should be the path to that plugin type's directory within your moodle codebase. You will already need to have copied your moodle codebase to this location, earlier in the dockerfile. This will load all of the PHP into the container's filesystem, meaning it will exist as soon as the container starts up without having to mount a volume from the host, and any changes to those files will be lost when the container shuts down. If you need to update the files, you will need to rebuild the container and redeploy it.

An alternative approach using volumes would be to manage all your moodle codebase in a directory on the host, then mount that directory onto your container at runtime. This will mean any changes made to the code are reflected "live".

The former approach is more appropriate for production deployment, while the latter is better suited to a development environment.

In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -

Maybe I don't understand how volumes work in Docker.

But still this is my demand and I have to carry it out

  by the commands:

RUN wget https://moodle.org/plugins/download.php/30209/report_growth_moodle43_2023101400.zip -P /bitnami/moodledata && \

     cd /bitnami/moodledata && \

     unzip report_growth_moodle43_2023101400.zip

I managed to download the plug-in from the internet.

My problem is that when it goes down to volume - moodledata

Everything works fine!!

But when I download the plug-in to its appropriate place in the moodle volume

He can't get off

I have no idea what the difference is between the volumes

Why does it manage to go down for one volume and not for the other????

In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I'm not really clear on what you mean here. Maybe if you can share your dockerfile (don't post it here, perhaps link to it on GitHub Gist/Pastebin or similar) so we can have a more complete picture of what you're doing, it will be easier make suggestions.

In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
I can't upload my dockerfile, I'll just give more details!
I created docker-compose that runs mariadb, moodle, phpmyadmin
Due to the fact that I wanted the option of adding the plugin when running moodle for the first time, I changed the moodle part to a dockerfile.

My goal is in the end - an initial run of a moodle website with specific plugins.

So what I'm trying to do is:
Adding lines in the dockerfile that download the relevant plug-in to the volume and add it to the moodle website
What I tried to do is by the lines of code:
RUN wget https://moodle.org/plugins/download.php/30209/report_growth_moodle43_2023101400.zip -P /bitnami/moodle/report&& \
cd /bitnami/moodle/report && \
unzip report_growth_moodle43_2023101400.zip
But for some reason I can't download the plug-in into the volume of moodle
Unlike anywhere else in Container where everything works fine.

I have no idea what the problem is! I would be very happy to answer
And thanks for all the attention so far!
In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

When you say "But for some reason I can't download the plug-in into the volume of moodle", what actually happens? Does the build fail? Is there any output from the wget command?

Also, can you share the portion of your docker-compose file that runs the moodle container?

In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
I have no output and no error, but the run stops and does not end.
At first I waited maybe it was a short wait but it continued for a long time.
Right now the screen is stuck with the following output:
mariadb | 2023-12-06 14:00:21 0 [Warning] 'proxies_priv' entry '@% root@4b29b593e7c8' ignored in --skip-name-resolve mode.mariadb | 2023-12-06 14:00:21 0 [Note] /opt/bitnami/mariadb/sbin/mysqld: ready for connections.
mariadb | Version: '11.0.3-MariaDB' socket: '/opt/bitnami/mariadb/tmp/mysql.sock' port: 3306 Source distribution

And when I check the moodle volume through the docker desktop, I only see the plug-in I tried to download
That is, everything that exists in the volume is overrun and only the plug-in enters in its place. (I check all this while the run is still stopped.)


docker-compose.yml
Moodle:
volumes:
- 'moodle_data:/bitnami/moodle'
- 'moodledata_data:/bitnami/moodledata'
build: .
ports:
- 80:8080
- 443:8443
depends_on:
- mariadb
networks:
- mynetwork

volumes:
  mariadb_data:
  moodle_data:
  moodledata_data:

In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Can you just confirm what command you ran that produced those "mariadb" output lines?

From the look of that you are mounting the host directory moodle_data as a volume on /bitnami/moodle. You should either be managing the code directly in there from the host and not try putting stuff there from the dockerfile, or you should not be mounting a volume there and only put code in /bitnami/moodle from the dockerfile. Trying to do both is probably the source of confusion here.

In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Ron Meske -
Roni, How I overcame this is to create a shell script that does the download and installation of your plugins. Include what is currently in your compose Run command in the shell script and then replace the Run command to execute the script. I map an external folder in the compose file towhere I keep the shell script so that it can be modified as needed.
In reply to Ron Meske

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
I think we are not talking about the same problem.
My problem is not how to download the plugin and add to volume . that is as I said I already succeeded.
But I have a problem that I don't understand why it happens.
Why for one volume (moodledata) everything works as required, while on the other hand for the desired volume (moodle) a problem arises!
Is there a difference between the two volumes???
Ron, your suggestion is correct but does not answer the problem.
I changed to a shell file but the problem still remains.
In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The best I can suggest is that you check the permissions of the download directory a) in the container and b) on the host. Also, as a test try removing the volumes from the docker compose file and see if you get the same results.

In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
The truth is that in all my recent attempts I delete the volumes and the container associated with moodle at every restart for fear that it does not run properly when it is not initialized from the beginning.
And regarding the permission check, I couldn't exactly figure out how to check it.
And again I will ask the question that bothers me: what is the difference between the moodle volume and the moodledata volume????
Because I feel like I'm working in vain because every running line I run
it is correct and written correctly because it works great on the moodledata volume but when I switch to work with the moodle volume the running stops for me in the middle of the construction
Maybe you can focus me what could be the specific problem in accessing the moodle volume????
In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Some things to check:

  • From the host, check the ownership and permissions on the moodle_data and moodledata_data directories. Use your file manager, or ln -la in the terminal
  • From inside the running container (run docker exec -it container_name /bin/bash to get a shell inside the container):
    • Check ownership and permissions of the mounted directories, ln -la again
    • Try creating a file in each volume (touch /bitnami/moodle/test.txt and touch /bitnami/moodledata/test.txt) and see if you get any errors.
In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
I tried to create files inside the different volumes (according to the commands you gave me) and it created them for me without any error, which shows that apparently there is no problem accessing the volumes
(Regardless, I couldn't understand how I can check permissions, I didn't understand the syntax of the commands: ln -la)
I will mention again: when I try to download the file into the moodle volume it does not give an error but stops the run in the middle which means that apparently there is no error
But something else I don't know what it is!
Maybe there is another idea that can create the problem: stopping the run without an error
And again, I am very grateful for your patience and time
In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I don't think there's much more help I can offer here, sorry.

In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
Thank you very much for all the time and patience you spent for me
I understand that I have a fundamental problem that is difficult to solve
I will try to continue solving it
Roni
In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Ron Meske -
I do agree with Mark that it is likely a permissions problem. Typically the Moodledata folder is set to be written to versus the Moodle folder is not.

Your issue is likely with the Bitnami image. You will find many occurrences of it in the forums and the recommendation is to always not use it. You will probably save time by creating your own docker file to build an image for Moodle as you will have more control over permissions and how you want it configured.
In reply to Ron Meske

תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by roni bar -
Ron, thank you very much for the answer, I was really in a difficult dilemma.
For the first time I understood that the problem was writing to the moodle folder.
Your advice seems very good to me!!
I would love to get more detail on how I can create my own docker file without bitnami
If you have docker-compose suitable for my needs it will help me a lot
My requirements: running a moodle site so that additional plugins will be added directly during its construction.
Thanks in advance!
I would very much appreciate an answer as soon as possible!
I have been sitting on this for many days.
In reply to roni bar

Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Moodle HQ publishes its own container based on this dockerfile: https://github.com/moodlehq/moodle-php-apache/blob/master/Dockerfile. It is used by https://github.com/moodlehq/moodle-docker to create a development environment with docker-compose. These should be useful references for how to create a basic Moodle docker container.

The docker project has very good and extensive documentation about writing Dockerfiles https://docs.docker.com/engine/reference/builder/.

Average of ratings:Useful (1)
In reply to Mark Johnson

תשובה ל: Re: תשובה ל: Re: Added plugin already in dockerfile

by mosa tair -

I ran into a very similar problem!

I will be happy to answer!

I read the post to the end and I want to clarify a few things:

Rony, you cannot execute the COPY or RUN commands in the same Dockerfile that executes FROM moodle because you are trying to copy/download the files to the bitnami/moodle routing that does not yet exist during the build. (created while running the container)

Hope I helped you, go ahead and succeed!


Now to my question:

like you said:

So when you run the Docker image, the plugins I wrote for my model system will be loaded directly for me.



I want to close a snapshot that contains my own plugins and installations.

My problem is, as I explained to you, that everything is done at the ENTRYPOINT - while the container is running, and now I don't have the option to add the plugins already when building the image.

I have been sitting on this for a long time!

Can someone help me??