0

I've run into an nginx limiting issue that requires me to extend config of my nginx dockerfile, I found a Dockerfile extension logic listed here but I'm having trouble getting it to work, I'm not sure what I'm supposed to use for the COPY . /app/ for because I don't need to copy anything into the image to my understanding, I just need that magic script.

Here is the whole Dockerfile for reference

FROM jwilder/nginx-proxy
COPY . /app/
RUN { \ 
    # Increased the number of worker_processes from any number to 4
    sed -i 's/\(worker_processes\s*\)[0-9]*;/\14;/' /etc/nginx/nginx.conf; \
    # Increased the number of worker_connections from any number to 19000
    sed -i 's/\(worker_connections\s*\)[0-9]*;/\119000;/' /etc/nginx/nginx.conf; \
}

Removing COPY doesn't work, the build context just gets huge (over 1GB) so I'm guessing it's grabbing everything in the repo it's in.

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75
  • 1
    One option is to use a `docker run -v` option to replace the configuration file when you run the image. This can't do an in-place edit -- you need to provide a complete config file -- but you also don't need a custom image for this approach. – David Maze Apr 04 '21 at 00:32
  • 1
    `the build context just gets huge (over 1GB) so I'm guessing it's grabbing everything in the repo it's in`, you may need a [.dockerignore](https://docs.docker.com/engine/reference/builder/#dockerignore-file) file – Bertrand Martel Apr 04 '21 at 02:37
  • @DavidMaze That's correct I learned, I was thinking it would just "know" the config haha – Kevin Danikowski Apr 04 '21 at 05:05

2 Answers2

1

wader from Github putting his app into the image. You can ignore that.

It is true, you have to remove the COPY-line and you will get the nginx-proxy with the changed settings.

Docker will always create a build context. The context contains a copy of ALL files which are in same working directory.
So if you run docker build ., then all files (and directories) in the current folder will be added to build context.
Never run docker build on your root- or home-directory.


According to KevinDanikowski's answer: Yes, his steps working, but these steps are not correct and doesn't explain the problem.

You have not to clone any git-repo to get the Dockerfile working.
In this case, it will work, because the linked repo from @KevinDanikowski is not really full.
It is much easier to create just a new folder and put the Dockerfile in there.

In BASH:

$ mkdir newFolder
$ cd newFolder
$ cat > Dockerfile << EOF
FROM jwilder/nginx-proxy

RUN { \ 
    # Increased the number of worker_processes from any number to 4
    sed -i 's/\(worker_processes\s*\)[0-9]*;/\14;/' /etc/nginx/nginx.conf; \
    # Increased the number of worker_connections from any number to 19000
    sed -i 's/\(worker_connections\s*\)[0-9]*;/\119000;/' /etc/nginx/nginx.conf; \
}
EOF
$ docker build .
akop
  • 5,981
  • 6
  • 24
  • 51
  • Yea I was wrongly thinking i could run the dockerfile from anywhere since it was pulling that image, just wasn't the case, it has to be from the actual directory like you had mentioned. – Kevin Danikowski Apr 04 '21 at 22:27
  • @KevinDanikowski so I solved your question? ;) – akop Apr 05 '21 at 06:24
  • sorry I was actually the one who solved it but I can't check it as solved until 48 hours later (idk why someone down voted it). I'll upvote yours though because it gives additional context – Kevin Danikowski Apr 05 '21 at 12:21
  • I was not the downvoter, but I don't see how your answer solves the question. – akop Apr 05 '21 at 12:29
  • "I found, and you need to run it in the repo for building that image. So in this case from https://github.com/nginx-proxy/nginx-proxy and replace the Dockerfile with your updated one here, and run it." , my mention in the Q of "build size ... 1GB" mean't I was running it from the wrong place, basically what your question added context to – Kevin Danikowski Apr 05 '21 at 12:41
  • @KevinDanikowski your solution is working, but this doesn't mean, that your steps are correct. Look at my edit. – akop Apr 07 '21 at 14:31
-2

It's called a derived dockerfile I found, and you need to run it in the repo for building that image (not in the repo that you're likely getting that 1GB build context from.

So the solution:

  1. Clone the origin repo https://github.com/nginx-proxy/nginx-proxy

  2. Replace the Dockerfile with your updated one here

  3. Run your docker build command

I just did this and pushed, publicly available as kmdanikowski/nginx-proxy but I recommend you do your own so it can be the most up to date.

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75
  • You could run the Dockerfile in the question (without the offending `COPY` line) from anywhere, in the same way you can build a "normal" image `FROM python:3.9` without actually having the Docker library image sources checked out. – David Maze Apr 04 '21 at 00:30
  • @DavidMaze I did attempt that, yet it didn't work. I thought you could, but at least in my experience that wasn't true. – Kevin Danikowski Apr 04 '21 at 04:59