user6136315
user6136315

Reputation: 705

reload nginx container on content change

I'm setting up nginx server using Docker. If I add a new file/directory to all-html,is that content need to loaded to nginx dynamically(without reloading the nginx)?

I can able to load the new contents only If rebuilding the image again (without cache). is there any way to setup the nginx configuration to dynamically load the content without rebuilding the docker image?

Dockerfile

FROM ubuntu:latest

RUN apt-get update
RUN apt-get install -y nginx
RUN rm /etc/nginx/nginx.conf

ADD nginx.conf /etc/nginx/

ADD web /usr/share/nginx/html/
ADD web /var/www/html/

RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 90

CMD service nginx start

nginx.conf

worker_processes 1;

events { worker_connections 1024; }

http {
    include    mime.types;
    sendfile on;
    server {
        root /usr/share/nginx/html/;
        index index.html;
        server_name localhost;
        listen 90;
        location /all-html {
               autoindex on;
        }
    }

}
ls  web/
all-html    icons       index.html  mime.types
ls  web/all-html/
1.html  ntf.zip 2.html

Upvotes: 1

Views: 3680

Answers (2)

Sreenivasa Reddy
Sreenivasa Reddy

Reputation: 304

Use VOLUME to mount the web directory, so that the files will be in sync and Nginx dynamically load the content without rebuilding the docker image.

You can mount the volume in Dockerfile or even while starting the container like below.

-v web:/var/www/html/

Upvotes: 1

machine424
machine424

Reputation: 155

You can mount a host directory as a volume inside the container, make changes in the host directory (they will propagate inside the container) and then docker exec ... nginx -s reload OR kill -s HUP, is that the bash snippet you mentioned ? Or you can run another processus inside the container that will periodically check for changes and reload the nginx process.

Upvotes: 1

Related Questions