I am confused, because it seems that an environment variable which is set in docker-compose.yml causes docker to rebuild my image on docker-compose up:
Dockerfile for apache_php_with_custom_docroot
FROM php:7.1.11-apache-jessie
# Set apache document root
ENV APACHE_DOCUMENT_ROOT /var/www/web
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
I'm building it with docker build -t apache_php_with_custom_docroot .
docker-compose.yml
version: "3"
services:
web:
image: apache_php_with_custom_docroot
environment:
- APACHE_DOCUMENT_ROOT=/var/www/anotherfolder
So, the strange thing to me is: It works to set the APACHE_DOCUMENT_ROOT. When I run docker-compose up -d apache uses the docroot /var/www/anotherfolder.
I was sure, when my image was build, then I can't change it in my docker-compose file. I read something about build parameters e.g. here: Docker-compose: Set a variable in env file and use it in Dockerfile
But I did not set build params. How does docker know, that he has to rebuild my image? Where can I read about the principles behind this?