New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a volume for /usr/share/nginx/html makes nginx produce garbage #24

Closed
felixrabe opened this Issue May 22, 2015 · 6 comments

Comments

Projects
None yet
4 participants
@felixrabe
Copy link

felixrabe commented May 22, 2015

This is on OS X 10.9 with Boot2Docker 1.6.2 (using AUFS) and Docker 1.6.2. Running the Nginx container with a volume for static files produces garbage.

docker run -v "$(pwd)/html:/usr/share/nginx/html" -p 80:80 -d nginx

html/index.html was originally (when I started the container):

Hey

Then I changed it to:

I have a different length than you think!

This has 42 bytes, including the trailing newline. When I use any browser to access this container, I get the original file content (padded with zero bytes), but the Content-Length matches the new version: (I'm using dnsmasq to map all *.docker domains to the Boot2Docker IP.)

felix-mba:funk fr$ curl -v http://garbage.docker/
* Adding handle: conn: 0x7f9d4a803a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f9d4a803a00) send_pipe: 1, recv_pipe: 0
* About to connect() to garbage.docker port 80 (#0)
*   Trying 192.168.59.103...
* Connected to garbage.docker (192.168.59.103) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.30.0
> Host: garbage.docker
> Accept: */*
> 
< HTTP/1.1 200 OK
* Server nginx/1.9.0 is not blacklisted
< Server: nginx/1.9.0
< Date: Fri, 22 May 2015 18:21:55 GMT
< Content-Type: text/html
< Content-Length: 42
< Last-Modified: Fri, 22 May 2015 18:21:54 GMT
< Connection: keep-alive
< ETag: "555f73c2-2a"
< Accept-Ranges: bytes
< 
Hey
* Connection #0 to host garbage.docker left intact
felix-mba:funk fr$ curl -s http://garbage.docker/ | hexdump -C
00000000  48 65 79 0a 00 00 00 00  00 00 00 00 00 00 00 00  |Hey.............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00                    |..........|
0000002a
felix-mba:funk fr$

Any ideas?

@felixrabe

This comment has been minimized.

Copy link
Author

felixrabe commented May 22, 2015

felix-mba:funk fr$ hexdump -C html/index.html 
00000000  49 20 68 61 76 65 20 61  20 64 69 66 66 65 72 65  |I have a differe|
00000010  6e 74 20 6c 65 6e 67 74  68 20 74 68 61 6e 20 79  |nt length than y|
00000020  6f 75 20 74 68 69 6e 6b  21 0a                    |ou think!.|
0000002a
felix-mba:funk fr$ 
@felixrabe

This comment has been minimized.

Copy link
Author

felixrabe commented May 22, 2015

See also boot2docker/boot2docker#652. This seems to be a VirtualBox bug.

@thresheek

This comment has been minimized.

Copy link
Member

thresheek commented May 22, 2015

Yeah, the first thing to try would be to reproduce the effect on a real machine.

@felixrabe

This comment has been minimized.

Copy link
Author

felixrabe commented May 22, 2015

The workaround I use is to set sendfile off. (Another might be to use NFS, as described in boot2docker/boot2docker#652 (comment), but I have not tested this myself.)

Dockerfile:

FROM nginx

COPY nginx.conf /etc/nginx/nginx.conf

nginx.conf: (just commented out the sendfile on; line)

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    #sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Closing as this is clearly reported to be a VirtualBox bug.

@zsmhub

This comment has been minimized.

Copy link

zsmhub commented Aug 6, 2017

First, thanks! But I have a question:
How to disable PHP caching when running PHP using Docker?
When I modify the Index.php I don't see my change.

@zbennett10

This comment has been minimized.

Copy link

zbennett10 commented Aug 12, 2017

+1 to using sendfile off in nginx - saved me a ton of time getting this to work with Docker Toolbox on Windows 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment