I'm trying to use sed to replace the text "localhost" in my nginx.conf with the IP address of my docker host (FYI. using docker machine locally, which is running docker on 192.168.99.100).
My nginx Dockerfile looks like this:
FROM nginx:alpine
ARG DOCKER_HOST
COPY ./nginx.conf /etc/nginx/nginx.conf
RUN sed -i 's/localhost/${DOCKER_HOST}/g' /etc/nginx/nginx.conf
EXPOSE 80
My nginx.conf file looks like this (note: majority removed for simplicity)
http {
sendfile on;
upstream epd {
server localhost:8080;
}
# ...
}
I'm expecting "localhost" to get replaced with "192.168.99.100", but it actually gets replaced with "${DOCKER_HOST}". This causes an error
host not found in upstream "${DOCKER_HOST}:8080"
I've tried a few other things, but I can't seem to get this working. I can confirm the DOCKER_HOST build arg is getting through to the Dockerfile via my docker compose script, as I can echo this out.
Many thanks for any responses...
Replace the single quotes '
around s/localhost/${DOCKER_HOST}/g
with double quotes "
. Variables will not be interpolated within single quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With