0

I am developping a website which I want to host inside a php-apache docker container.
I use the following command to run the container:

docker run -dit --restart unless-stopped --name my_www -p 8080:80 -v /path/to/repo:/var/www/html/ php:7.4-apache

Since I bind the repository containing the code as a volume to the container, I expect the website to "update live" when I change the code locally. I had this right behaviour last time I tried but I am now unable to get it back.
When I check the website locally at 127.0.0.1 everything is ok and changes are taken into account normaly, but they do not propagate into the docker container... For some reason, the files in the docker are stuck to an old version of the code, an old "stat" of the repository...
Any ideas how I can manage to fix this and preview changes live ?

Gabriel C
  • 141
  • 1
  • 10
  • `When I check the website locally at 127.0.0.1` - does it mean you have another webserver already running on your machine, outside Docker, and with a docroot of `/path/to/repo`? And it does not match the content in the Docker server at `http://127.0.0.1:8080`? – Don't Panic Apr 05 '20 at 23:21
  • I use Brackets IDE to develop, and it has a Preview functionnality which opens a new tab, for exemple: `http://127.0.0.1:37329/`. This way I see live changes. However when looking at 127.0.0.1:8080 (or public_ip:8080) to look at the docker version, it is not updated live. Looking at it right now it is updated, but I made the changes yesterday, so I restarted my computer in between and it looks like this forces in some way the update inside docker, but what I would like is to update live without restart. – Gabriel C Apr 06 '20 at 12:20
  • Could it be Apache or your browser caching the old files? Have you tried checking the files on disk from inside/outside the container (eg `docker exec container ls -l /path/to/changed/file/` to check timestamps, or `cat` it to see if your change is there)? There are plenty of questions here on SO about changes not propagating ([example](https://stackoverflow.com/questions/52897000/docker-files-from-volume-not-updated-in-target)), any of them helpful? – Don't Panic Apr 06 '20 at 23:47
  • Hmm interesting, I did as you suggested and found that there is a wrong timezone in the docker container (2h shift, it is set to UTC but I'm in France) but I don't thing it is a problem, because files are updated, the content is updated live, but the changes are not visible on the browser. For me this suggests that Apache is caching files, isn't it ? – Gabriel C Apr 07 '20 at 11:27
  • I have no idea how to disable apache caching in the docker container – Gabriel C Apr 07 '20 at 11:42
  • I tried [this solution](https://stackoverflow.com/a/11724596/6401758), written in .htaccess file at the root of my site, but it does nothing, even after restarting docker container – Gabriel C Apr 07 '20 at 11:59
  • 1
    As you say, timezone in the container is not relevant here, only that the timestamps show the file is being updated correctly. Does hitting reload in your browser show the right content? That definitely means it is being cached, either by the browser or the server. Your browser's devtools will also show this - check the network tab, and inspect the requests for the content that is not refreshing. At least in Chrome, there is a "Disable Cache" checkbox, make sure that is not checked. Responses cached by the browser will say something about 'cache' in the Size col. 304s mean server cached. – Don't Panic Apr 09 '20 at 00:35
  • Ok, so I checked as you suggested in the devtools of Chrome and it was indeed caching everything. I figured out a way to disable caching from the server, I simply enabled the module "expires" with `a2enmod expires` and that did the trick, now I can see changes live. Thank you for your kind help and useful indications it helped a lot to debug ! – Gabriel C Apr 11 '20 at 19:53
  • Glad we cracked it :) – Don't Panic Apr 11 '20 at 23:08

1 Answers1

0

Credits to @Don't Panic for helping to debug.
The browser was caching everything so I couldn't see changes live.
The solution was to enable the "expires" apache module inside the docker container:

$ docker exec -it <container_id> bash
root@<container_id>:# a2enmod expires
root@<container_id>:# exit
$ docker restart my_www

Et voilà :)

Gabriel C
  • 141
  • 1
  • 10