Mautic setup not persisting in Docker

118 views Asked by At

I'm trying to create an image for Mautic + Composer according to the directions here.

I've put together a Dockerfile that does the setup, based on the official image on github. When I run it, Mautic launches as expected and takes me through the install process to set up the database, etc., and it's all smooth sailing so far.

If I have to restart the container for any reason, however, I am brought back to the install process each time, which wipes out the database.

I looked over the Dockerfile on github, and read the Docker documentation on volumes, and everything I looked at seems to be telling me I did it correctly, but the official image persists properly when the container is restarted, where mine does not. I'm new to Docker so I've probably overlooked something, but I've exhausted everything I can think of.

Dockerfile:

FROM php:7.4-apache

LABEL vendor="Mautic"
LABEL maintainer="Luiz Eduardo Oliveira Fonseca <[email protected]>"

# Define Mautic volume to persist data
VOLUME /var/www/html

EXPOSE 80

# Install PHP extensions
RUN apt-get update && apt-get install --no-install-recommends -y \
    cron \
    git \
    wget \
    sudo \
    libc-client-dev \
    libicu-dev \
    libkrb5-dev \
    libmcrypt-dev \
    libzip-dev \
    libssl-dev \
    libz-dev \
    libonig-dev \
    unzip \
    zip \
    libpng-dev \
    libjpeg-dev \
    vim \
    sed \
    && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
    && rm -rf /var/lib/apt/lists/* \
    && rm /etc/cron.daily/*

RUN pecl install mcrypt-1.0.3

RUN docker-php-ext-configure imap --with-imap --with-imap-ssl --with-kerberos \
    && docker-php-ext-configure opcache --enable-opcache \
    && docker-php-ext-configure gd --enable-gd --with-jpeg  \
    && docker-php-ext-install imap gd intl mbstring mysqli pdo_mysql zip opcache bcmath sockets exif \
    && docker-php-ext-enable imap gd intl mbstring mcrypt mysqli pdo_mysql zip opcache bcmath sockets exif

# Setting PHP properties
ENV PHP_INI_DATE_TIMEZONE='UTC' \
    PHP_MEMORY_LIMIT=1024M \
    PHP_MAX_UPLOAD=128M \
    PHP_MAX_EXECUTION_TIME=300

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

# Create Mautic project with composer
WORKDIR /var/www
RUN rm -r html \
    && composer create-project mautic/recommended-project:^4 html --no-interaction

# Update Mautic core files
WORKDIR /var/www/html
RUN composer update mautic/core-lib --with-dependencies 

# Copy Mautic files to docroot folder
WORKDIR /var/www/html/docroot
COPY media/ media/
COPY plugins/ plugins/
COPY translations/ translations/
COPY themes/ themes/
COPY var/ var/
COPY index.php index.php
COPY app/config/ app/config/
COPY app/config/local.php /app/config/local.php

# By default enable cron jobs
ENV MAUTIC_RUN_CRON_JOBS true

# By default disable automatic migrations
ENV MAUTIC_RUN_MIGRATIONS false

# Copy init scripts 
COPY common/docker-entrypoint.sh /entrypoint.sh
COPY common/makeconfig.php /makeconfig.php
COPY common/makedb.php /makedb.php
COPY common/mautic.crontab /etc/cron.d/mautic

# Change web root to /var/www/html/docroot
RUN chmod 644 /etc/cron.d/mautic \
    && sed -ie 's,/var/www/html,/var/www/html/docroot,g' /etc/apache2/sites-available/000-default.conf \
    && chown -R www-data:www-data /var/www/html/docroot/

# Enable apache rewrite module and update web config
RUN a2enmod rewrite
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /etc/apache2/apache2.conf
RUN { \
  echo 'IncludeOptional conf.d/*.conf'; \
} >> /etc/apache2/apache2.conf \
  && mkdir /etc/apache2/conf.d

# Apply necessary permissions and start
RUN ["chmod", "+x", "/entrypoint.sh"]
RUN chmod -R 755 /var/www/html/docroot/
ENTRYPOINT ["/entrypoint.sh"]
CMD ["apache2-foreground"]
0

There are 0 answers