|
| 1 | +FROM debian:%%DEBIAN_VERSION%%-slim |
| 2 | + |
| 3 | +LABEL maintainer="NGINX Docker Maintainers < [email protected]>" |
| 4 | + |
| 5 | +ENV NGINX_VERSION %%NGINX_VERSION%% |
| 6 | +ENV NJS_VERSION %%NJS_VERSION%% |
| 7 | +ENV PKG_RELEASE %%PKG_RELEASE%% |
| 8 | + |
| 9 | +RUN set -x \ |
| 10 | +# create nginx user/group first, to be consistent throughout docker variants |
| 11 | + && addgroup --system --gid 101 nginx \ |
| 12 | + && adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx \ |
| 13 | + && apt-get update \ |
| 14 | + && apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates \ |
| 15 | + && \ |
| 16 | + NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \ |
| 17 | + found=''; \ |
| 18 | + for server in \ |
| 19 | + ha.pool.sks-keyservers.net \ |
| 20 | + hkp://keyserver.ubuntu.com:80 \ |
| 21 | + hkp://p80.pool.sks-keyservers.net:80 \ |
| 22 | + pgp.mit.edu \ |
| 23 | + ; do \ |
| 24 | + echo "Fetching GPG key $NGINX_GPGKEY from $server"; \ |
| 25 | + apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \ |
| 26 | + done; \ |
| 27 | + test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \ |
| 28 | + apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \ |
| 29 | + && dpkgArch="$(dpkg --print-architecture)" \ |
| 30 | + && nginxPackages="%%PACKAGES%% |
| 31 | + " \ |
| 32 | + && case "$dpkgArch" in \ |
| 33 | + amd64|i386) \ |
| 34 | +# arches officialy built by upstream |
| 35 | + echo "deb %%PACKAGEREPO%% %%DEBIAN_VERSION%% nginx" >> /etc/apt/sources.list.d/nginx.list \ |
| 36 | + && apt-get update \ |
| 37 | + ;; \ |
| 38 | + *) \ |
| 39 | +# we're on an architecture upstream doesn't officially build for |
| 40 | +# let's build binaries from the published source packages |
| 41 | + echo "deb-src %%PACKAGEREPO%% %%DEBIAN_VERSION%% nginx" >> /etc/apt/sources.list.d/nginx.list \ |
| 42 | + \ |
| 43 | +# new directory for storing sources and .deb files |
| 44 | + && tempDir="$(mktemp -d)" \ |
| 45 | + && chmod 777 "$tempDir" \ |
| 46 | +# (777 to ensure APT's "_apt" user can access it too) |
| 47 | + \ |
| 48 | +# save list of currently-installed packages so build dependencies can be cleanly removed later |
| 49 | + && savedAptMark="$(apt-mark showmanual)" \ |
| 50 | + \ |
| 51 | +# build .deb files from upstream's source packages (which are verified by apt-get) |
| 52 | + && apt-get update \ |
| 53 | + && apt-get build-dep -y $nginxPackages \ |
| 54 | + && ( \ |
| 55 | + cd "$tempDir" \ |
| 56 | + && DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \ |
| 57 | + apt-get source --compile $nginxPackages \ |
| 58 | + ) \ |
| 59 | +# we don't remove APT lists here because they get re-downloaded and removed later |
| 60 | + \ |
| 61 | +# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies |
| 62 | +# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies) |
| 63 | + && apt-mark showmanual | xargs apt-mark auto > /dev/null \ |
| 64 | + && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \ |
| 65 | + \ |
| 66 | +# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be) |
| 67 | + && ls -lAFh "$tempDir" \ |
| 68 | + && ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \ |
| 69 | + && grep '^Package: ' "$tempDir/Packages" \ |
| 70 | + && echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \ |
| 71 | +# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes") |
| 72 | +# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied) |
| 73 | +# ... |
| 74 | +# E: Failed to fetch store:/var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied) |
| 75 | + && apt-get -o Acquire::GzipIndexes=false update \ |
| 76 | + ;; \ |
| 77 | + esac \ |
| 78 | + \ |
| 79 | + && apt-get install --no-install-recommends --no-install-suggests -y \ |
| 80 | + $nginxPackages \ |
| 81 | + gettext-base \ |
| 82 | + curl \ |
| 83 | + && apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \ |
| 84 | + \ |
| 85 | +# if we have leftovers from building, let's purge them (including extra, unnecessary build deps) |
| 86 | + && if [ -n "$tempDir" ]; then \ |
| 87 | + apt-get purge -y --auto-remove \ |
| 88 | + && rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \ |
| 89 | + fi \ |
| 90 | +# forward request and error logs to docker log collector |
| 91 | + && ln -sf /dev/stdout /var/log/nginx/access.log \ |
| 92 | + && ln -sf /dev/stderr /var/log/nginx/error.log \ |
| 93 | +# create a docker-entrypoint.d directory |
| 94 | + && mkdir /docker-entrypoint.d |
| 95 | + |
| 96 | +COPY docker-entrypoint.sh / |
| 97 | +COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d |
| 98 | +COPY 20-envsubst-on-templates.sh /docker-entrypoint.d |
| 99 | +ENTRYPOINT ["/docker-entrypoint.sh"] |
| 100 | + |
| 101 | +EXPOSE 80 |
| 102 | + |
| 103 | +STOPSIGNAL SIGTERM |
| 104 | + |
| 105 | +CMD ["nginx", "-g", "daemon off;"] |
0 commit comments