在Packer脚本中更改文件(使用sed)会使文件保持不变

目前我正在研究使用封隔器和dockerbuild造一条生产线。 这是我的packer.json:

{ "builders": [{ "type": "docker", "image": "php:7.0-apache", "commit": true }], "provisioners": [ { "type": "file", "source": "./", "destination": "/var/www/html/" }, { "type": "shell", "inline": [ "chown -R www-data:www-data /var/www/html", "sed '/<Directory \\/var\\/www\\/>/,/<\\/Directory>/ s/AllowOverride None/AllowOverride all/' /etc/apache2/apache2.conf", "sed '/<VirtualHost/,/<\\/VirtualHost>/ s/DocumentRoot \\/var\\/www\\/html/DocumentRoot \\/var\\/www\\/html\\/web/' /etc/apache2/sites-enabled/000-default.conf" ] } ] } 

provisioners部分中的Shell脚本包含用于更改apacheconfiguration中的AllowOverrideDocumentRootvariables的一些sed命令。

当封隔器运行这个脚本它工作得很好,我得到一个积极的sed输出,所以sed似乎工作正常。 但是在docker图像中文件没有改变。 复制文件供应商中的file工作正常。

我究竟做错了什么?

看来你在你的sed命令中缺less-i (或--in-place )标志。 试试:

 "sed -i <expression> <file>"