Dockerising Contao 4
Last year, we moved the website of our department from Typo3 to Contao version 3. I wrote about that in Dockerising a Contao website and Dockerising a Contao website II. Now it was time to upgrade from Contao version 3 to 4. And as usual: Things have changed… So, how to jail a Contao 4 into a Docker container?
Similar to Contao 3, we use two images for our Contao 4 site. One is a general Contao 4 installation, the other one is our personalised version.
A general Contao 4 image
The general Contao 4 is based on an PHP image that includes an Apache webserver. In addition, we need to
- install a few dependencies,
- enable some Apache modules,
- install some extra PHP extensions,
- install Composer,
- and finally use Composer to install Contao.
This time, I outsourced the installation of Composer into a seperate script install-composer.sh:
Thus, you’ll find a current composer installation in /composer
.
The Dockerfile for the general image then boils down to the following:
PLEASE NOTE: sSMTP is not maintained anymore! Please switch to
msmtp
, for example, as I explained in Migrating from sSMTP to msmtp.
This image includes the package for sSMTP to enable support for mails. To learn how to configure sSMTP, have a look into my earlier article Mail support for Docker’s php:fpm.
Alltogether, this gives us a proper recipe to get a dockerised Contao 4. It is also available from the Docker Hub as binfalse/contao.
A personalised Contao 4 image
Based on that general Docker image, you can now create your personalised Docker image. There is a template in the corresponding Github repository.
A few things worth mentioning:
- After installing additional contao modules, you should clear Contao’s cache using:
- Contao still does not respect the
HTTP_X_FORWARDED_PROTO
… Thus, if running behind a reverse proxy, Contao assumes its accessed through plain HTTP and won’t deliver HTTPS links. I explained that in Contao 3: HTTPS vs HTTP. However, the workaround for Contao 3 doesn’t work anymore - and there seems to be no proper solution for Contao 4. Therefore, we need to inject some code into theapp.php
… Yes, you read correctly… Ugly, but anyway, can easily be done using:
- The composer-based installation apparently fails to set the files’ links. Thus we need to do it manually:
Everything else should be pretty self-explaining…
Tying things together
Use Docker-Compose or whatever to spawn a container of your personalised image (similar to Contao 3: Docker-Compose).
Just make sure, you mount a few things correctly into the container:
- your files need to go to
/var/www/html/files
- Contao’s configuration belongs to
/var/www/html/system/config/*.php
, as usual - Symfony’s configuration belongs to
/var/www/html/app/config/parameters.yml
and/var/www/html/app/config/config.yml
- For the mail configuration see Mail support for Docker’s php:fpm
Please note, that the database connection must be configured in Symfony’s parameters.yml
! Instead of Contao’s localconfig.php
, as it used to be for Contao 3.
- network (68) ,
- software (160) ,
- university (46) ,
- website (22) ,
- administration (43) ,
- web (86) ,
- php (16) ,
- programming (16)
- apache (15) ,
- config (21) ,
- explained (43) ,
- contao (4) ,
- docker (17) ,
- network (81) ,
- university (42) ,
- curl (8) ,
- fix (13) ,
- http (6) ,
- job (10) ,
- php (8) ,
- programming (75) ,
- snippet (13) ,
- ssl (10) ,
- mail (11) ,
- ssmtp (5)
Leave a comment
There are multiple options to leave a comment: