安装为 docker 卷的文件在保存在 docker 之外时损坏

File mounted as docker volume becomes corrupt when saved outside docker

在我的主机中,我有这个目录:

/Users/gezimhome/projects/ziprecipes.net/zip-recipes/src

我将其安装到我的 docker 容器中:

/usr/share/nginx/html/wordpress/wp-content/plugins/zip-recipes

如果我在 docker 之外修改以下文件(例如添加新行): /Users/gezimhome/projects/ziprecipes.net/zip-recipes/src/plugins/VisitorRating/scripts/main.js,我在浏览器中收到语法错误:

野生动物园:

Chrome:

如果我进入 docker 容器并打开文件 (/usr/share/nginx/html/wordpress/wp-content/plugins/zip-recipes/plugins/VisitorRating/scripts/main.js) 并再次 保存 它而不做任何更改,错误是走了。

我知道这会令人费解。

我已经在我的主机中尝试了多个 Editors/IDEs 来保存文件。没有区别。

更新:哇,我在 docker 内部编辑文件时和从外部编辑文件时都将文件保存在 docker 中发现没有区别的差异:

cp /usr/share/nginx/html/wordpress/wp-content/plugins/zip-recipes/plugins/VisitorRating/scripts/main.js /host.js
# editted the file in same way inside docker
cp /usr/share/nginx/html/wordpress/wp-content/plugins/zip-recipes/plugins/VisitorRating/scripts/main.js /docker.js
root@219a4126d14a:/# diff /host.js /docker.js
root@219a4126d14a:/#

原来是nginx的sendfile设置造成的

为了修复它,我更改了我的 nginx 网站配置文件(/etc/nginx/sites-enabled/nginx_wordpress 在我的例子中)设置 sendfile off 如下:

server {
        listen   8080;
        server_name zrdn;

        sendfile off;
        ...
}