Issue
I have set up dockerfile with making changes to config files with sed. The image is a simple rtmp restreamer.
The lines in dockerfile go like:
RUN sed -i 's/ytkey/${YOUTUBE_KEY}/g' /etc/nginx/nginx.conf &&\
sed -i 's/fbkey/${FACEBOOK_KEY}/g' /etc/nginx/nginx.conf
i set up ENV at the beginning
ENV YOUTUBE_KEY=default FACEBOOK_KEY=default
but after building the image it doesn't replace ytkey or fbkey as default but inputs a string ${YOUTUBE_KEY}.
I have tried running
RUN sed -i 's/ytkey/\${YOUTUBE_KEY}/g' /etc/nginx/nginx.conf &&\
sed -i 's/fbkey/\${FACEBOOK_KEY}/g' /etc/nginx/nginx.conf
But had the same result. Is it a problem with sed (having the env in '') or something else? Is there an alternative to sed that works with dockerfile? Or maybe i'm doing things completely the wrong way?
Solution
You can use double quotation marks around environment variables like this:
RUN sed -i 's/user/'"${YOUTUBE_KEY}"'/g' /etc/nginx/nginx.conf &&\
sed -i 's/pid/'"${FACEBOOK_KEY}"'/g' /etc/nginx/nginx.conf
Answered By - vine-nam Answer Checked By - Robin (WPSolving Admin)