this is my scenario, I have a Laravel 8 application that I'm trying to deploy using AWS ECS through AWS Fargate.
This is the useful part of my dockerfile:
### ... Previous composer and npm stages
FROM php:8.0-cli-alpine
# Concatenated RUN commands
RUN apk add --no-cache .........
RUN mkdir -p /run/apache2 \
&& rm -rf /tmp/*
# Apache configuration
COPY docker/fargate/apache.conf /etc/apache2/conf.d
# PHP configuration
COPY docker/fargate/php.ini /etc/php8/conf.d
# Script permission
ADD docker/fargate/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
# Copy files from NPM
WORKDIR /var/www/html
COPY --from=build-npm /var/www/html /var/www/html
RUN chmod -R 777 /var/www/html
COPY docker/fargate/.env.fargate /var/www/html/.env
# Run script
EXPOSE 80
ENTRYPOINT ["/docker-entrypoint.sh"]
And this is the docker-entrypoint.sh file
#!/bin/sh
# Cache
php artisan route:cache --quiet
php artisan config:cache --quiet
# Permissions
# On Alpine Apache's user and groups are apache
chown -R apache:apache /var/www/html
chgrp -R apache /var/www/html/bootstrap/cache
chmod -R ug+rwx /var/www/html/bootstrap/cache
# Launch the httpd in foreground
rm -rf /run/apache2/* || true && /usr/sbin/httpd -DFOREGROUND
Now, the deployed application works fine and I can browse my application.
But, I would like to mount a persistent volume at "/var/www/html" to be able to persist web sessions and other data. So, the volume exists but only seems to be mounted before the entrypoint command ran and, in this way, all the previous copied file vanish.
I tried adding these lines into the entrypoint script as first lines:
mkdir -p /var/www/html/bootstrap/cache
mkdir -p /var/www/html/public
It creates the folder correctly, so it confirms that the volume is mounted after the entrypoint starts.
Which is the correct way to achieve a goal like the one described here? I would like to persist data and overwrite them when container starts, if needed.