使用 Dockerfile 在某些匹配后无法写入新行
Failed to write new line after certain match using Dockerfile
我正在尝试在使用 Dockerfile 找到一些匹配项后写入新行,但它无法按照我的代码工作。我在下面解释我的代码。
/etc/nginx/conf.d/ubot-nginx.conf
::
server {
listen 90;
server_name ubot_nginx;
location / {
# proxy_pass http://flask_app:5005;
try_files $uri @app;
# Do not change this
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location @app {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
location /site {
# rewrite ^/static(.*) / break;
# root /static;
alias /app/static/angular;
}
}
在上面的文件中,我需要在 alias /app/static/angular;
之后写一些新行 i.e-try_files $uri $uri/ /index.html =404;
所以我在 Dockerfile
.
中使用下面的命令
RUN sed '/^alias /app/static/angular.*/a try_files $uri $uri/ /index.html =404;' /etc/nginx/conf.d/ubot-nginx.conf
我需要在这里构建图像时,上面给出的新行应该根据找到的特定匹配项来编写,这在我的情况下没有发生。请问有人可以帮助我吗?
尝试sed -i -E 's|^(\s*alias /app/static/angular.*)|\n\ttry_files $uri $uri/ /index.html =404;|' /etc/nginx/conf.d/ubot-nginx.conf
我正在尝试在使用 Dockerfile 找到一些匹配项后写入新行,但它无法按照我的代码工作。我在下面解释我的代码。
/etc/nginx/conf.d/ubot-nginx.conf
::
server {
listen 90;
server_name ubot_nginx;
location / {
# proxy_pass http://flask_app:5005;
try_files $uri @app;
# Do not change this
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location @app {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
location /site {
# rewrite ^/static(.*) / break;
# root /static;
alias /app/static/angular;
}
}
在上面的文件中,我需要在 alias /app/static/angular;
之后写一些新行 i.e-try_files $uri $uri/ /index.html =404;
所以我在 Dockerfile
.
RUN sed '/^alias /app/static/angular.*/a try_files $uri $uri/ /index.html =404;' /etc/nginx/conf.d/ubot-nginx.conf
我需要在这里构建图像时,上面给出的新行应该根据找到的特定匹配项来编写,这在我的情况下没有发生。请问有人可以帮助我吗?
尝试sed -i -E 's|^(\s*alias /app/static/angular.*)|\n\ttry_files $uri $uri/ /index.html =404;|' /etc/nginx/conf.d/ubot-nginx.conf