Docker Community Forums

Share and learn in the Docker community.

Overriding COPY with VOLUME on container

Hello, I am having difficulty using a single Dockerfile for both development and production.
In the Dockerfile I am copying the project directory to image COPY . /var/www/html. It works as expected.
I am trying to overwrite the path by setting the -v flag with docker run. It will load the current path and any updates since build, but does not show any updates to files on host after container is started.
Is this something that is possible to have with my current setup?

Project structure

.docker
    |
    - Dockerfile
app/
public/
resources/
...
...

Build:
docker build -t my_app -f .docker/Dockerfile .

Run:
docker run -it -p 8080:80 -e APP_ENV=local -v /var/www/html my_app

Dockerfile

FROM php:7.2.15-apache-stretch

ENV APACHE_DOCUMENT_ROOT /var/www/html/public

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

ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
    PHP_OPCACHE_MAX_ACCELERATED_FILES=8000 \
    PHP_OPCACHE_MEMORY_CONSUMPTION=128

COPY .docker/start.sh /usr/local/bin/start
COPY .docker/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
COPY . /var/www/html

RUN chown -R www-data:www-data /var/www \
    && chmod +x /usr/local/bin/start \
    && docker-php-ext-install opcache pdo_mysql \
    && pecl install xdebug \
    && docker-php-ext-enable xdebug

CMD ["/usr/local/bin/start"]