Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload Nginx in during docker build

I am trying to install nginx (and then nodejs) in my container. I have my own nginx config files in nginx/ folder:

# --- Release with Alpine ----
FROM phusion/baseimage:0.10.1

# Create app directory
WORKDIR /app

RUN apt-get update \
    && apt-get -y install nginx

RUN ls /etc/nginx
COPY nginx/nginx.conf /etc/nginx/nginx.conf
RUN ls /etc/nginx

RUN ls /etc/nginx/sites-enabled
RUN rm /etc/nginx/sites-enabled/default
COPY nginx/serverlogic /etc/nginx/sites-enabled/serverlogic
RUN ls /etc/nginx/sites-enabled

RUN nginx -s reload

RUN echo "$PWD FINALFINALFINAL" && ls

EXPOSE 8080

But I get an error on RUN nginx -s reload line saying: "nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)". What is that?

p.s. Is there some image on docker hub with ubuntu, node.js and nginx installed? I want to put them in one container for simplicity.

like image 629
Ruslan Plastun Avatar asked Jul 22 '18 15:07

Ruslan Plastun


Video Answer


1 Answers

nginx -s reload can only be used when nginx is running. It sends a signal to the master process of nginx which itself notifies the worker processes.

The problem here is, that you do not have a nginx instance running during your build process. So you are unable to reload it.

It is not a real problem though. Since nginx is not running, you do not need to reload it. After starting nginx (with an runit init file when using the phusion base image), it will be loading your provided configuration.

That said, I would not recommend running multiple services in a single container though. It is easy enough with docker-compose to orchestrate multiple containers nowadays.

like image 94
ShrimpPhaser Avatar answered Sep 28 '22 04:09

ShrimpPhaser