4

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

user3538553
  • 1,443
  • 3
  • 15
  • 21

2 Answers2

2

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.

Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102
  • I guess i don't even need the COPY command. thank you! how can i mark your answer as correct? – user3538553 Feb 04 '15 at 05:59
  • No you don't need the COPY command if you're using volumes. But it does allow you to distribute a working version of your image - you can use volumes while developing, then rebuild the image to ship it with up-to-date code. There should be a tick symbol next to my answer you can click to accept, IIRC. – Adrian Mouat Feb 04 '15 at 11:10
  • i see 'share' and 'edit' at the bottom but that's it. maybe i don't have enough points. – user3538553 Feb 05 '15 at 17:36
  • @user3538553 There should be a tick symbol below the points at the left. Don't worry about it though :) – Adrian Mouat Feb 05 '15 at 17:57
  • I have similar problem with nginx Docker image. When I update file in mounted folder and refreshes page in browser - there is nothing changes. Container runs with 'docker run -d -P -v $HOME/site:/usr/share/nginx/html --name mysite nginx' command. Interesting that response headers such as Content-Length, ETag and Last-Modified shows correct new updated data, but response is stayed unchanged... – Dmitry Jun 12 '15 at 20:14
  • And when I delete/create or rename file - it works like a charm. (I use Boot2Docker for mac, perhaps it matters) – Dmitry Jun 12 '15 at 20:24
  • @DmitryAkinin please don't ask questions in comments! Open a question if you like :) – Adrian Mouat Jun 12 '15 at 20:37
  • 1
    Sorry for this, I think my question is not so important to open new Question page. I was wrong :) By the way -- I found issue, that describes my problem - https://github.com/nginxinc/docker-nginx/issues/24. Perhaps it will be helpful for someone. – Dmitry Jun 15 '15 at 19:15
1

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

宫宜栋
  • 57
  • 1