sed
-Specific Advice: Use An Insert, Not A Replace
The below still assumes an implementation of the nonstandard -i
option compatible with GNU sed
.
RUN sed -i -e '2i/bootstrap_mongo_on_k8s.sh &' /usr/local/bin/docker-entrypoint.sh
...or, if formulated using the below advice:
RUN ["sed","-i","-e","2i/bootstrap_mongo_on_k8s.sh &","/usr/local/bin/docker-entrypoint.sh"]
General Advice: Passing Commands Through Docker Safely
Generally, the safest way to pass exact content to a RUN
command is as a JSON list.
If the original, tested shell command you want to run in Docker is:
sed -i 's/#!\/bin\/bash/#!\/bin\/bash\n\/bootstrap_mongo_on_k8s.sh \&\n/' /usr/local/bin/docker-entrypoint.sh
...the literal strings it's composed of are, one per line, as follows:
sed
-i
s/#!\/bin\/bash/#!\/bin\/bash\n\/bootstrap_mongo_on_k8s.sh \&\n/
/usr/local/bin/docker-entrypoint.sh
As a JSON list, this would be:
["sed","-i","s/#!\\/bin\\/bash/#!\\/bin\\/bash\\n\\/bootstrap_mongo_on_k8s.sh \\&\\n/","/usr/local/bin/docker-entrypoint.sh"]
Note the doubled backslashes. This can be generated with a command of the form:
printf '%s\n' \
sed \
-i \
's/#!\/bin\/bash/#!\/bin\/bash\n\/bootstrap_mongo_on_k8s.sh \&\n/' /usr/local/bin/docker-entrypoint.sh \
| jq -Rnc '[inputs]'