I suspected the problem may come with Azure file through SMB. So I created a new wordpress container with a local /var/www/html folder (not a volume from Azure file). The the problem disappeared.
So the problem is the SMB Azure file?
I then use the following command to host a python http server and mount the azure volume to it.
sudo docker run -it –rm –name my-running-script -p 8000:8000 -v vol3:/usr/src/myapp -w /usr/src/myapp python:2 python -m SimpleHTTPServer 8000
There is no problem at all with this python server.
The only thing I can think is that the apache config in the wordpress container does not work well with SMB volume, especially when a big file is served in fast speed.
I then mounted the azure file volume to a php container without wordpress
sudo docker run –rm -p 8000:80 –name my-apache-php-app -v vol3:/var/www/html php:7.0-apache
The problem can be reproduced. So there is nothing to do with wordpress.
I then tried the same thing on apache httpd
docker run –rm –name my-apache-app -p 8000:80 -v vol3:/usr/local/apache2/htdocs/ httpd:2.4
I can reproduce the problem. So that the problem is apache, not php.
I run apache with local dir
sudo docker run –rm –name my-apache-app -p 8000:80 -v “$PWD”:/usr/local/apache2/htdocs/ httpd:2.4
It worked well, the problem disappeared; which comes to the summary, docker apache is not working well with Docker Volume Driver.
The file I used to test is only 3.7M. Good news is that wordpress can still work well with this problem. I think that wordpress files are small enough to hide this problem.
I then used php CLI as a php web host
sudo docker run -it –rm –name my-running-script -p 8000:8000 -v vol3:/usr/src/myapp -w /usr/src/myapp php:7.0-cli php -S 0.0.0.0:8000
This time, the problem is gone for directly file access (better than apache). But once I download the file with a download.php file, the problem comes back.
I used readfile function in the download.php file to read a local file
I then changed the local file URL to a HTTP URL, then it worked. This is really dirty, because the php file go through internet to reach it’s own server to read a local file as a remote file.
Now comes to the solution.
run a python http server
sudo docker run -it -d –name python_http -p 8001:80 -v vol4:/usr/src/myapp -w /usr/src/myapp python:2 python -m SimpleHTTPServer 80
Add this http server to the same network as wordpress server
docker network connect –alias python_http_host wp-net python_http
Then in the download.php file, use http://python_http/... in the readfile function to read a remote file from another docker container, which is actually a local file.
Problem solved!!! But this requires a new docker container running.