How do I turn sendfile off in a docker instance

2.3k views Asked by At

I have a nginx docker instance running. In the docker instance there is a file called /etc/nginx/nginx.conf

It has the following settings

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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" 

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

    sendfile        on;
    ....
}

I run the docker instance by running with the following command.

docker run -d -P -v /Users/user/site:/usr/share/nginx/html --name mysite nginx

How would I run the above command but have it change the config setting to turn off sendfile?

This answer looks similar to mine. Would I need to create a build file? Im a bit confused.

2

There are 2 answers

0
Thomasleveil On BEST ANSWER

Just inject your own config file as a volume.

Let say you have a conf file in /tmp, then you can run the container with :

docker run -d -P -v /tmp/my.conf:/etc/nginx/nginx.conf -v /Users/user/site:/usr/share/nginx/html --name mysite nginx
1
gmuslera On

There are a lot of alternatives:

  • have the nginx.conf in a volume, so you can load different ones for different containers (or use the default one if no mount volume parameters passed)
  • not run directly nginx, but a shell script that does that change with sed, and then load nginx (or load nginx directly if no change needed)
  • in the nginx.conf or the bash that load nginx, be aware of environment variables passed from the docker command line, and define a few to change the container behavior in defined ways.
  • a mix of the above, mount a volume on launching with just the bash script (that modifies conf and launch nginx) and launch that script on run.
    • create a new image based on the nginx one that just modifies the config file, it will weight just the difference between both containers (the config file).

There are more variations of this, using higher level tools, but this one are simple enough