Search code examples
phpsymfonydockervolumereboot

Docker Apache Container looses static site data after reboot


I have a Docker container that serves some php-Pages with Symfony. It also has a connection to the database that works perfectly fine. The root directory is /var/www/html/public and the rough structure of /var/www/html is as follows (-files and [directories]):

[/var/www/html]
  -Dockerfile
  -package.json
  -vendor
  -src
  -someotherstuff
  [public]
     index.php
     favicon.ico
     [CSS]
     [Javascript]
     [uploads -> this folder is a volume, users can upload their own data]
        -userFileA
        -userFileB

When I start the container with this command everything works great:

docker run -d --restart always --name myContainerName -e DATABASE_URL=mysql://mysql:${DB_PW}@mysql:3306/myDbName -e APP_ENV=${ENV_TYPE} -e APP_SECRET=******** -v myapp_data:/var/www/html/public/uploads -p 127.0.0.1:82:80 --net mysql_net myId/myRepo –

After I reboot the server all files except the "uploads"-folder inside public get deleted though and the server files look as follows:

[/var/www/html]
  -Dockerfile
  -package.json
  -vendor
  -src
  -someotherstuff
  [public]
     [uploads -> this folder is a volume]
        -userFileA
        -userFileB

Now the website is completetly broken because the index.php in the public-folder is missing.

I don't understand why this happens and only on reboot. If there was a conflict between the volume and the other folder shouldn't that also happen on the initial run? And why do only files inside public get deleted and not outside? I am really confused and most info I can find for this topics are erros because a volume is set up incorrectly but my volume works fine and is actually the only thing still properly filled after a reboot

This is my Dockerfile and the commands I use to build it:

#docker build --tag=myId/myRepo .
#docker push myId/myRepo
FROM php:7.2-apache
ENV DB_HOST=mysql:3306 \
    DB_USER=myDbUser \
    DB_NAME=myDbName
COPY php.ini "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install pdo_mysql && a2enmod rewrite
COPY ./ /var/www/html/
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
VOLUME /var/www/html/public/uploads/

Solution

  • My mistake was to specify VOLUME /var/www/html/public/uploads/ in the Dockerfile

    After removing this line and only making the folder a volume with docker run -v ... the error didn't occur anymore.