|
| 1 | +# Adding third-party modules to nginx official image |
| 2 | + |
| 3 | +It's possible to extend a mainline image with third-party modules either from |
| 4 | +your own instuctions following a simple filesystem layout/syntax using |
| 5 | +`build_module.sh` helper script, or failing back to package sources from |
| 6 | +`https://hg.nginx.org/pkg-oss`. |
| 7 | + |
| 8 | +## Usage |
| 9 | + |
| 10 | +``` |
| 11 | +$ docker build --build-arg ENABLED_MODULES="ndk lua" -t my-nginx-with-lua . |
| 12 | +``` |
| 13 | +This command will attempt to build an image called `my-nginx-with-lua` based on |
| 14 | +official nginx docker hub image with two modules: `ndk` and `lua`. |
| 15 | +By default, a Debian-based image will be used. If you wish to use Alpine |
| 16 | +instead, add `-f Dockerfile.alpine` to the command line. |
| 17 | + |
| 18 | +The build script will look for module build definition files on filesystem |
| 19 | +directory under the same name as the module (and resulting package) and if |
| 20 | +those are not found will try to look up requested modules in the pkg-oss |
| 21 | +repository. |
| 22 | + |
| 23 | +For well-known modules we maintain a set of build sources packages over at |
| 24 | +`pkg-oss`, so it's probably a good idea to rely on those instead of providing |
| 25 | +your own implementation. |
| 26 | + |
| 27 | +As of the time of writing this README, the following modules and their versions |
| 28 | +are available from `pkg-oss` repository: |
| 29 | + |
| 30 | +``` |
| 31 | +/pkg-oss $ LC_ALL=C make -C debian list-all-modules |
| 32 | +make: Entering directory '/pkg-oss/debian' |
| 33 | +brotli 1.0.0-1 |
| 34 | +encrypted-session 0.08-1 |
| 35 | +geoip 1.19.6-1 |
| 36 | +geoip2 3.3-1 |
| 37 | +headers-more 0.33-1 |
| 38 | +image-filter 1.19.6-1 |
| 39 | +lua 0.10.19-1 |
| 40 | +modsecurity 1.0.1-1 |
| 41 | +ndk 0.3.1-1 |
| 42 | +njs 0.5.0-1 |
| 43 | +opentracing 0.10.0-1 |
| 44 | +passenger 6.0.6-1 |
| 45 | +perl 1.19.6-1 |
| 46 | +rtmp 1.2.1-1 |
| 47 | +set-misc 0.32-1 |
| 48 | +subs-filter 0.6.4-1 |
| 49 | +xslt 1.19.6-1 |
| 50 | +make: Leaving directory '/pkg-oss/debian' |
| 51 | +``` |
| 52 | + |
| 53 | +If you still want to provide your own instructions for a specific module, |
| 54 | +organize the build directory in a following way, e.g. for `echo` module: |
| 55 | + |
| 56 | +``` |
| 57 | +docker-nginx/modules $ tree echo |
| 58 | +echo |
| 59 | +├── build-deps |
| 60 | +├── prebuild |
| 61 | +└── source |
| 62 | +
|
| 63 | +0 directories, 3 files |
| 64 | +``` |
| 65 | + |
| 66 | +The scripts expect one file to always exist for a module you wish to build |
| 67 | +manually: `source`. It should contain a link to a zip/tarball source code of a |
| 68 | +module you want to build. In `build-deps` you can specify build dependencies |
| 69 | +for a module as found in Debian or Alpine repositories. `prebuild` is a shell |
| 70 | +script (make it `chmod +x prebuild`!) that will be executed prior to building |
| 71 | +the module but after installing the dependencies, so it can be used to install |
| 72 | +additional build dependencies if they are not available from Debian or Alpine. |
| 73 | +Keep in mind that those dependencies wont be automatically copied to the |
| 74 | +resulting image and if you're building a library, build it statically. |
| 75 | + |
| 76 | +Once the build is done in the builder image, the built packages are copied over |
| 77 | +to resulting image and installed via apt/apk. The resulting image will be |
| 78 | +tagged and can be used the same way as an official docker hub image. |
| 79 | + |
| 80 | +Note that we can not provide any support for those modifications and in no way |
| 81 | +guarantee they will work as nice as a build without third-party modules. If |
| 82 | +you encounter any issues running your image with the modules enabled, please |
| 83 | +reproduce with a vanilla image first. |
0 commit comments