Sign inSign up

binfalse/contao

By binfalse

•Updated about 5 years ago

Image for running a Contao-based website

Image
1

4.8K

binfalse/contao repository overview

⁠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 etc
  • templates/ - themes and layout adjustments etc
  • system/config/*.php - configuration for Contao
  • app/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 $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 $PATH/files/:/var/www/html/files/ \
    -v $PATH/templates/:/var/www/html/templates/ \
    -v $PATH/system/config/localconfig.php:/var/www/html/system/config/localconfig.php \
    -v $PATH/app/config/parameters.yml:/var/www/html/app/config/parameters.yml \
    conato-personalised

This basically mounts your files from 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.

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 $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:
        - $PATH/files:/var/www/html/files
        - $PATH/templates:/var/www/html/templates:ro
        - $PATH/system/config/localconfig.php:/var/www/html/system/config/localconfig.php
        - $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:
        - $PATH/database:/var/lib/mysql

This will create 2 containers:

  • contao based on this image, all user-based files are mounted into the proper locations
  • contao_db a MariaDB⁠ to provide a MySQL server

To make Contao speak to the MariaDB server you need to configure the database connection in $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.

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/>.

Tag summary

Content type

Image

Digest

Size

254.5 MB

Last updated

about 5 years ago

docker pull binfalse/contao