I’ve the following Dockerfile:
FROM nginx
ARG BuildMode
ENV BuildMode=${BuildMode}
RUN echo BuildMode
COPY ./dist/omg-portal-frontend /usr/share/nginx/html
COPY ./nginx/default.${BuildMode}conf /etc/nginx/conf.d/default.conf
So do I need to add the following command? (to restart the Nginx service)
RUN service nginx restart
When I do, I get the following error:
[emerg] host not found in upstream "ppd-omg-backend-service.azure.omgcom.net" in /etc/nginx/conf.d/default.conf:17
Line 17:
proxy_pass http://ppd-omg-backend-service.azure.omgcom.net/;
Can anyone help me with this? When I remove the command, I get build success, but I’m not sure if the container is reflecting the latest config changes…
You don't need any sort of RUN ... restart
command.
The error you're getting indicates that Nginx is in fact seeing your custom configuration; that host name won't be in the standard image's default.conf
file.
In the case of the nginx
image, its Dockerfile ends with the line
CMD ["nginx", "-g", "daemon off;"]
so when you docker run
a container, it runs a new foreground Nginx server. At that point Nginx will read its configuration file, because it's starting up for the first time. You don't need to do anything in your Dockerfile to cause this to happen.
More generally, a container only runs a single process. It doesn't "run services", and it doesn't make sense to "restart a service". Often the service
command outright won't work. Running processes aren't persisted in the image, so there won't be a server of any sort until you run a container and the CMD
or ENTRYPOINT
happens.