Home > Enterprise >  Failed to write new line after certain match using Dockerfile
Failed to write new line after certain match using Dockerfile

Time:12-23

I am trying to write new line after some match found using Dockerfile but its not working as per my code. I am explaining my code below.

/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(.*) /$1 break;
        # root /static;
        alias /app/static/angular;
    }
}

In the above file I need to write some new line i.e-try_files $uri $uri/ /index.html =404; after alias /app/static/angular; so for that I am using below command in my Dockerfile.

RUN sed '/^alias /app/static/angular.*/a try_files $uri $uri/ /index.html =404;' /etc/nginx/conf.d/ubot-nginx.conf

I need here when the image will built the new line given above should be written as per particular match found which is not happening in my case. Please anybody can help me on this ?

CodePudding user response:

Try sed -i -E 's|^(\s*alias /app/static/angular.*)|\1\n\ttry_files $uri $uri/ /index.html =404;|' /etc/nginx/conf.d/ubot-nginx.conf

  • Related