Hosting directly on server or in docker

Does it makes sense to run farmOS in docker on a RAM constrained server?

What are the advantages of the installation in docker vs. directly on the server?
Are there any disadvantages?
Would the docker container need a lot of RAM especially as the database grows with lots of pictures and data?

2 Likes

I haven’t found any direct discussion/benchmarks about memory usage differences yet, but I did find some good discussions about performance differences in general;

Naively, I would imagine there should be some memory footprint differences if different versions of shared objects have to be loaded separately for each container. That said, I don’t know whether this has a significant impact in practice.

Also, I wouldn’t be a good software engineer if I didn’t first stress the point of not optimizing until you know you need to. Go with whatever is cheapest/easiest/already-available until you know you need to do more than that. In this context, I think that means using docker if that’s easiest to get setup and maintain until you have data to show that doesn’t work for your use-case. (Of course, don’t lose whatever effort you’ve expended so far. Test on a similar vm or something so you can just throw it away if the test doesn’t pan out.)

2 Likes

The main benefit that Docker containers provide is encapsulation and consistency/reproducibility. The farmOS image contains all the dependencies (Apache, PHP, GEOS, BCMath), in the correct versions that we know work, pre-configured for farmOS.

This keeps your server itself “clean” in the sense that you don’t need to install anything other than Docker on it, which is handy if you need to move to another server (because of a crash, major upgrade, etc etc). The Docker container will run the same on any server with Docker.

My understanding is that Docker is different from a VM in that it is just a thin layer between the host system resources (CPU, RAM, etc) and that code running in the container. It is not emulating an entire operating system. Therefore, the CPU and RAM usage of the container will be comparable to running farmOS outside of a container (maybe a little bit of overhead, but negligible).

Database and files are NOT stored in the Docker container itself (if you set up your volumes correctly). They are stored on the host server and mounted into the container as a volume/directory.

Another benefit is security: if a major security issue is discovered in Drupal or farmOS, and an attacker exploits it to gain access to your server, they are still inside the container and cannot access the host server itself (unless they also have a Docker exploit to break out), so there is an added layer.

It is especially useful for development. I can run the same Docker container on my laptop that I run on a server. So if I want to develop new features, I can copy a backup of my site down to my laptop, do development there, and I know that it will work the same on the production server.

The biggest disadvantage is that you have to learn and understand Docker. And that’s understandably a hurdle that doesn’t make sense for some! So if the benefits described above don’t outweigh that extra layer, then stick with what you’re familiar with!

There have been a number of people who have reported issues with missing dependencies when they install farmOS outside of Docker (usually on shared hosting where they don’t have the ability to install things like GEOS). But, if you do have full server access, you can also look to the farmOS Dockerfile to see exactly what you need! It is just a series of steps that set up the server (container) with what farmOS needs to run. :slight_smile:

2 Likes

I also want to respond to this specific point:

Does it makes sense to run farmOS in docker on a RAM constrained server?

Drupal (which farmOS is built on) is notoriously RAM hungry (for many reasons). So regardless of whether or not you are using Docker, it will perform better with more RAM.

The farmOS Docker container sets the PHP memory_limit=256M which means each Apache worker could use up to that (and there can be multiple Apache workers if you have a lot of users accessing it). I know of people who have installed farmOS on a Raspberry Pi with 512 MB of RAM. I probably wouldn’t recommend anything less than that, but your mileage may vary!

1 Like

@Symbioquine Thank you for your reply. It’s quite interesting that the docker installations are not that much slower but reduce the network speed a bit compared to direct installations.
Your other comment about what one should use is almost philosophical :wink: and very good to be kept in mind.
@mstenta I have now understood that docker is different to a normal VM which also contains its own OS. The added security is actually a good argument to use docker.
As you said and I read the files can be stored inside or outside of the container.
What would you actually suggest? Outside is probably more secure but inside could enable moving from one server to another one without loosing any data. Right?

1 Like

As you said and I read the files can be stored inside or outside of the container.
What would you actually suggest?

This is a very important point: anything that you want to “persist” MUST be stored outside of the Docker container and mounted in as a volume.

Docker containers should be thought of as ephemeral. You should be able to destroy the container, create a new one, mount the same folders into it, and be back up and running with your data. So anything you want to SAVE (which, in the case of Drupal 7/farmOS would be the database and the sites directory), should be mounted into the container as a volume.

This looks like a good intro (haven’t read it, I admit, but I like the Game Boy analogy :slight_smile: ): Understanding Docker as if it were a Game Boy | by James Audretsch | Medium

1 Like

@mstenta Thank you very much for raising this very important point!! This is completely different from what I had thought.
Using farmOS with Docker sounds like it would be much easier to update to a new farmOS version compared to hosting it directly on the server. Since the database and sites directory would be outside of the container. At the moment I still run the first installation because I did not have the time to update the farmOS version and was worried I would destroy my database again.
Thanks for the medium link! Really nice read.
I just found out that my old home server does not support docker (no intel cpu). From what you wrote before it sounds like I could put my data on lets say a external hdd + install docker on my computer and run farmOS. Once I get a server that supports docker I could move the data to that server + install docker and run farmOS on that server.
Am I right with this assumtion?
Is there anything that might lead to data loss in this process?

1 Like

Using farmOS with Docker sounds like it would be much easier to update to a new farmOS version compared to hosting it directly on the server.

I hope so! But always backup your code+database+files before updating. :slight_smile:

See: Installing farmOS | farmOS

Once I get a server that supports docker I could move the data to that server + install docker and run farmOS on that server.
Am I right with this assumtion?

Yes! I would recommend keeping your existing installation running, and set up the Docker installation in parallel, so you can experiment with migrating without affecting the original. Then once you’re confident that you can migrate smoothly, you can make the switch.

Is there anything that might lead to data loss in this process?

As long as you set it up and test it separately from the original installation, and are backing up your original, you should be OK.

Rule #1: Backups! :slight_smile:

2 Likes

I recently read somewhere that with old farmOS or docker? versions there had been issues with I think ARM CPUs (I think the discussion resolved around raspberry and docker).
Does the current farmOS version run with the same good performance on Intel and ARM CPUs?

1 Like

Yea I remember that discussion (vaguely). I think that initially Docker was only available on x86 architectures, but that has since changed and now it is possible to build the farmOS Docker image on ARM. However, you need to run docker build yourself, it isn’t possible to docker pull it from Docker Hub.

I can’t speak to performance differences between x86 and ARM because I haven’t used ARM with farmOS myself much at all. The main thing that will slow down the performance on a Raspberry Pi is the limited RAM I believe - but the newer Pis have more, so I’d be curious to see how they do!

2 Likes

Found the old thread: https://github.com/farmOS/farmOS/issues/58

1 Like

Yea im really interested in this as well.
Especially w the Pi4 out now.

1 Like