Docker image for CONTAO
The Dockerfile compiles into a Docker image for a plain Contao 4 CMS instance. The Dockerfile-personalised can be used to create an image including individual extensions and settings.
Usage
A detailed explanation on how to use the images to run a Contao website is available at Dockerising Contao 4.
The Contao site in the image from the Dockerfile is basically fully functional. It contains a plain Contao installation. However, it does not contain any plugins yet. Thus, you should use the image to create a personalised Docker image locallyr., The file Dockerfile-personalised may help as a template.
From that personalised image, all you need to do is mounting personalised files "over" the default versions into the image. Typically you would mount:
files/
- those are your uploaded images etctemplates/
- themes and layout adjustments etcsystem/config/*.php
- configuration for Contaoapp/config/*.yml
- configuration for Symfony
plus maybe other configuration files in system/config/
and app/config/
...
Simple Example
Let's say you keep your files in $CONTAO_PATH
and your personalised Docker image is called conato-personalised
, then you would run your website as:
docker run --rm -it \
-p 8080:80 \
-v $CONTAO_PATH/files/:/var/www/html/files/ \
-v $CONTAO_PATH/templates/:/var/www/html/templates/ \
-v $CONTAO_PATH/system/config/localconfig.php:/var/www/html/system/config/localconfig.php \
-v $CONTAO_PATH/app/config/parameters.yml:/var/www/html/app/config/parameters.yml \
conato-personalised
This basically mounts your files from CONTAO_PATH
to the proper locations in /var/www/html
of the container and bind its port 80
to port 8080
of your server. Thus, you should be able to access the Contao instance at example.com:8080
.
About mounting of config files
Take note that $CONTAO_PATH/system/config/localconfig.php
and $CONTAO_PATH/app/config/parameters.yml
need to exist on your local machine. Otherwise docker might create them as directories. If you mount existing or empty config files, you might need to attach to the container once it's running to adjust permissions on those files (This is a short command to do just that docker exec -it $(docker ps -aqf "name=app") bash -c 'chown www-data:www-data /var/www/html/app/config/parameters.yml && chown www-data:www-data /var/www/html/system/config/localconfig.php'
). Otherwise contao will not be able to install, because it cannot overwrite or read the files.
If you want to start with a fresh install and you're okay with using a docker-volume to store your config files, you can just omit mounting the config files.
Database
Depending on your configuration you may want to link a MySQL container etc.
Using Docker-Compose and a MySQL Database
Let's again say your individual data is stored in $CONTAO_PATH
and you want to run the website using a MySQL database, then you can compose the following containers
version: '2'
services:
contao:
build: /path/to/personalised/Dockerfile
restart: unless-stopped
container_name: contao
links:
- contao_db
ports:
- "8080:80"
volumes:
- $CONTAO_PATH/files:/var/www/html/files
- $CONTAO_PATH/templates:/var/www/html/templates:ro
- $CONTAO_PATH/system/config/localconfig.php:/var/www/html/system/config/localconfig.php
- $CONTAO_PATH/app/config/parameters.yml:/var/www/html/app/config/parameters.yml
contao_db:
image: mariadb
restart: always
container_name: contao_db
environment:
MYSQL_DATABASE: contao_database
MYSQL_USER: contao_user
MYSQL_PASSWORD: contao_password
MYSQL_ROOT_PASSWORD: very_secret
volumes:
- $CONTAO_PATH/database:/var/lib/mysql
This will create 2 containers:
contao
based on this image, all user-based files are mounted into the proper locationscontao_db
a MariaDB to provide a MySQL server
Prefill database configuration (instead of using installer)
To make Contao speak to the MariaDB server you need to configure the database connection in $CONTAO_PATH/app/config/parameters.yml
just like:
parameters:
database_host: contao_db
database_port: 3306
database_user: contao_user
database_password: contao_password
database_name: contao_database
secret: XXXXXXXXRANDOMXXXXXXXX
Here, the database should be accessible at contao_db:3306
, as it is setup in the compose file above.
Apache configuration
If you're running contao with "Rewrite URLs" using an .htaccess
you also need to update Apache's configuration to allow for rewrites. Thus, you may for example mount the follwoing file to /etc/apache2/sites-available/000-default.conf
:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/>
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This tells Apache to allow everything in any .htaccess
file in /var/www
.
Mail support
This image comes with sSMTP installed. If you need support for email with your Contao installation, you just need to mount two more files into the container:
Tell PHP to mail through sSMTP
The following file tells PHP to use the ssmtp
binary for mailing. Just mount the file to /usr/local/etc/php/conf.d/mail.ini
:
[mail function]
sendmail_path = "/usr/sbin/ssmtp -t"
Configure sSMTP
The sSMTP configuration is very easy. The following few lines may already be sufficient, when mounted to /etc/ssmtp/ssmtp.conf
:
FromLineOverride=YES
mailhub=mail.server.tld
hostname=php-fpm.yourdomain.tld
For more information read the documentation in my blog and the Arch Linux wiki on sSMTP or the Debian wiki on sSMTP.
LICENSE
Docker Image for Contao
Copyright (C) 2019 Martin Scharm <https://binfalse.de/contact/>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.