Search code examples
dockerdocker-composedockerfile

Docker does not sync folders from host to container


I have tried numerous different combinations on the docker-compose.yml file.

when this line :

- .:/var/www/html

changed to this :

- *:/var/www/html

Then it will copy over the files in the working directory but there is no sync. Ive tried surrounding the line with qoutes, changing the dot to ./ but no results. var/www/html is either empty or has files in it only when using * but no sync happens.

Here are my Dockerfile

FROM php:7.3.0-apache

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && apt-get update && apt-get install -y git libzip-dev unzip \
    && docker-php-ext-install zip \
    && a2enmod rewrite headers

COPY . /var/www/html/

COPY ./config/vhost.conf /etc/apache2/sites-available/000-default.conf

and docker-compose.yml.

version: '3.4'

services:
    app:
        ports:
            - 80:80
        environment:
            - APACHE_DOCUMENT_ROOT=/var/www/html/app/public
        build:
            context: .
        volumes:
            - .:/var/www/html

EDIT : Update. I tried removing the copy line, only worked so as to create an empty html dir on the container. As far as how i check, I do docker exec -it on the runnint container and just do an ls command on the html dir. I have thus far reinstalled docker toolbox and noticed there is a gui with it... I did not see any volumes when doing docker volume ls but the volume is shown in Kitematic. However, the dir on the host machine is NOT what one would expect, it is not the folder on drive d that docker-compose is in, but instead a folder in my documents. Trying to change it to the correct one on the gui and it says invalid dir. I remember reading somewhere that docker has limited access to the host filesystem and i am wondering if I have not missed a step here and should instead share the entire drive D with docker.

EDIT 2 : Added the folder on drive d to the vm named default into shared folders list, restarted all and still no dice. How can i specify a location on drive d?


Solution

  • If you want to keep your folder sync between host and container, then you'll need to mount it instead of copying it: check this documentation

    For your problem, you need to remove COPY . /var/www/html/ from Dockerfile

    You could also check this post.