Introduction

Since I've gotten Flarum to run on a single docker container, I've learned a lot about docker and docker-compose.
In short, I was stupid back then. Now I think I got it right.

Code on GitHub

I worked on a fork from the official repository: https://github.com/nadi106/flarum
PR was made for the official repo: flarum/flarum61

Instructions

Assuming you've got Docker and docker-compose installed, run the following commands:

git clone https://github.com/nadi106/flarum.git -b feature/docker-compose
cd flarum
docker run --rm -it -v $PWD:/app composer install
# (windows powershell) docker run --rm -it -v ${pwd}:/app comopser install
docker-compose up -d

And access flarum from localhost:8080.

Initial setup

Use the following fields for the DB to work:

  • MySQL Host: mariadb
  • MySQL Username: flarum
  • MySQL Password: flarumpass

Other fields can be of your choosing.

Please explain

  • You should know what cd and git clone do.
  • (optional) docker run --rm -it -v $PWD:/app composer install will install all of the dependencies required by Flarum, without downloading Composer (you can instead download and install composer if you'd like).
  • docker-compose up -d will read the docker-compose.yml file and start the containers inside.

More info

docker-compose.yml

The compose file specifies to run the following containers:

  • nginx:alpine - web server for handling http requests.
  • flarum-fpm - a custom image based on php:7.2-fpm-alpine which adds required PHP dependencies for Flarum to run.
  • mariadb:10.4 - a database container.
Docker volumes
  • The DB container saves its data on a docker volume which is created by docker-compose. This means the data will remain even if you delete the container.
  • The git root directory is being mounted on both the web and php containers so that they can serve the requested pages.
  • Also, nginx is configured with nginx/flarum.conf with a simple configuration which can be updated if need be.

Stopping the server

docker-compose down

Found Something Wrong?

Comment on the pull request on GitHub.

    2 months later

    nadi106 I am getting "Something went wrong while trying to load the full version of this site. Try hard-refreshing this page to fix the error." after I successfully installed it. When I load the site, it shows this error.
    BTW, MySQL DBname: flarum (missing in your doc 🙂 )
    I have asked multiple people to install it, they all get the same error.

      peterlu found the issue.
      docker-compose.yml says
      ports:
      - 8080:80

      after install, config.php needs a bit tweak:
      change
      'url' => 'http://localhost',
      to
      'url' => 'http://localhost:8080',

      I think this is a Flarum bug (maybe I am wrong). I shouldn't need to tweak the config.php though.

      nadi106 the average page load TTFB is at 6s (OMG) without data on some 3 years old mac. A brand new mac pro is running at 1.8s. Interesting to see how fast it runs on a server or Azure/AWS container.

        • [deleted]

        peterlu the average page load TTFB is at 6s

        WTF ?? 6 seconds ?? What is it - a calculator ?

          [deleted] Docker with default settings has issue with disk performance (Windows/Mac), result is a slow loading of the vendor folder (lot of small files).
          So it's Docker problem, not Flarum

          Options to fix it: http://blog.michaelperrin.fr/2017/04/14/docker-for-mac-on-a-symfony-app/

          I had a similar problem with Sylius eCommerce framework (Docker moved to Linux VM).
          Windows/Mac - 30-40 seconds page loading on i7 8700k, 16GB RAM, NVMe SSD.
          Linux - without problems.

            7 days later

            [deleted]
            now it is 6 seconds for page loading on a 7G azure production server, when this happens:
            https://discuss.flarum.org/d/22611-tags-module-fails-when-there-are-hundreds-or-thousands-of-tags

            When we do stress test with lots of posts, it is running ok. But when we run stress test with lots of tags, system/DB just hangs. Laravel framework (the base framework of Flarum) and the ORM model is known to have problems when the query is not written properly. We are looking into the problem to see if the Tags module can be refined. Maybe Flarum core product team can help look into it as well.

            Flarum is a very promising platform (it is PHP).

              peterlu
              We run Flarum on an on premise Kubernetes cluster on a small instance with 230 tags and no issues on performances (response time is around 500ms event if it is behind 2 reverse proxies). Maybe we do not reached the threshold of tags but we have probably much less cpu/memory capabilities than yours (1.8cpu, 3GB of ram).

              In your stress test the problem start to appear at which count of tags ?

                5 days later

                rdarcel try 10k primary tags, and 30k secondary tags(3 secondary tags per primary tag), you will see what I mean🙂 If 10k primary tags is too much for you, try 1k or 3k to start with.

                peterlu Maybe Flarum core product team can help look into it as well.

                It is certainly something we should look into. Will bring this to light for @Franz as well who is working on some performance improvements before stable.

                10 months later

                Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0". You are running 7.2.34. in /var/www/vendor/composer/platform_check.php on line 24

                  zhuhoudong this is an old tutorial (Flarum moves quickly from beta to beta and major breaking changes were released during 2020). It might not be compatible with the latest Flarum version.

                  That being said, what command gives you the error you shared? Flarum does not (yet) requires PHP 7.3 as of beta 14, so it's probably another package that's causing the issue.

                    zhuhoudong Hi, from the top of my head, try this:

                    • edit the first line of flarum-fpm.dockerfile to update PHP version (from 7.2 to 7.3)
                    • rebuild the image
                    • run docker-compose up -d

                    I think this should solve the PHP dependency issue.

                      nadi106 Thanks. New issue:

                      Warning: file_put_contents(/var/www/public/../storage/sessions/46OJsvuTjdB9XTW20dY3SdETwebCJpXXs1UbuPTZ): failed to open stream: Permission denied in /var/www/vendor/illuminate/filesystem/Filesystem.php on line 133

                      Fatal error: Uncaught Laminas\HttpHandlerRunner\Exception\EmitterException: Unable to emit response; headers already sent in /var/www/vendor/laminas/laminas-httphandlerrunner/src/Exception/EmitterException.php:19 Stack trace: #0 /var/www/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitterTrait.php(36): Laminas\HttpHandlerRunner\Exception\EmitterException::forHeadersSent() #1 /var/www/vendor/laminas/laminas-httphandlerrunner/src/Emitter/SapiEmitter.php(27): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->assertNoPreviousOutput() #2 /var/www/vendor/laminas/laminas-httphandlerrunner/src/RequestHandlerRunner.php(98): Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emit(Object(Laminas\Diactoros\Response\HtmlResponse)) #3 /var/www/vendor/flarum/core/src/Http/Server.php(42): Laminas\HttpHandlerRunner\RequestHandlerRunner->run() #4 /var/www/public/index.php(22): Flarum\Http\Server->listen() #5 {main} thrown in /var/www/vendor/laminas/laminas-httphandlerrunner/src/Exception/EmitterException.php on line 19

                        zhuhoudong solved:

                        [root@monitorcenter flarum]# cd ..
                        [root@monitorcenter wwwroot]# chmod -R 777 flarum
                        [root@monitorcenter wwwroot]# cd flarum/

                          zhuhoudong chmod-ing with 777 permissions is not recommended and possesses a security concern. Consider fixing the issue by having the files owned by the proper user/group (sometimes www-data but may vary)