user3538553
user3538553

Reputation: 1483

How to disable Nginx caching when running Nginx using Docker

I use the official nginx docker image (https://registry.hub.docker.com/_/nginx/). When I modify the Index.html I don't see my change. Setting sendfile off in nginx.conf didn't help.

I only see the change if i rebuild my image.

Here is my Dockerfile:

FROM nginx
COPY . /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

And that's the commands I use to build and run it:

docker build -t some-nginx .
docker run --name app1 -p 80:80 -v $(pwd):/user/share/nginx/html -d some-nginx

Thank you

Upvotes: 4

Views: 5644

Answers (2)

宫宜栋
宫宜栋

Reputation: 57

Just modify sendfile off in nginx.conf file can be work.

Upvotes: 1

Adrian Mouat
Adrian Mouat

Reputation: 46480

It's not caching. Once a file is copied into a container image (using the COPY instruction), modifying it from the host will have no effect - it's a different file.

You've attempted to overwrite the file by bind-mounting a volume from the host using the -v argument to docker run. This will work - you will now be using the same file on host and container, except you made a typo - it should be /usr not /user.

Upvotes: 2

Related Questions