Skip to content

Commit

Permalink
use multistage build to reduce final image size
Browse files Browse the repository at this point in the history
  • Loading branch information
ignidis committed Jun 1, 2019
1 parent 0f9e5f0 commit bbf2e7d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 30 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
This is a Dockerfile and build bash script for the OFFICIAL NGINX ORG Distribution.
This is a Dockerfile and a bash build script for the OFFICIAL NGINX ORG Distribution.

This can be used as it is for deploying NGINX to a Docker or Openshift environment, or as base image for applications.

It is based on CENTOS - 7 at the time i write this - but it should be quite simple to convert for Debian derivates.

This image exposes only port 8080 and 8443 - eventhough the bare server is bound only to 8080 and HTTP - but it would quite easy to start the image binding /etc/nginx and a for example /opt/wwwroot to host provided volumes containing a persistent configuration and web content.
The image is meant to run NGINX using a NON-ROOT user, per default UID 9001 is used, but you can change to another UID at build time.
Keep in mind that the NGINX user needs access to the host volumes , should you mount content.
Expand Down
72 changes: 44 additions & 28 deletions stable/amd64/centos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,11 @@ FROM centos:7
# Build Time Arguments
#
ARG NAME
ARG NGINX_VERSION
ARG NGINX_VERSION
ARG NGINX_REPO
ARG NGINX_SHORT_REPO
ARG NGINX_SVC_NAME
ARG NGINX_SVC_UID


#
# Do some bookeeping
#
ENV SUMMARY="Platform for running nginx $NGINX_VERSION-$NGINX_SHORT_REPO or building nginx-based application" \
DESCRIPTION="Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP \
protocols, with a strong focus on high concurrency, performance and low memory usage. The container \
image provides a containerized packaging of the nginx $NGINX_VERSION-$NGINX_SHORT_REPO daemon. The image can be used \
as a base image for other applications based on nginx $NGINX_VERSION-$NGINX_SHORT_REPO web server. \
Nginx server image can be extended using source-to-image tool."

LABEL summary="${SUMMARY}" \
description="${DESCRIPTION}" \
io.k8s.description="${DESCRIPTION}" \
io.k8s.display-name="NGINX ${NGINX_SHORT_REPO}-${NGINX_VERSION}" \
io.openshift.expose-services="8080:http" \
io.openshift.expose-services="8443:https" \
io.openshift.tags="builder,${NAME},${NAME}-$NGINX_SHORT_REPO-${NGINX_VER}" \
name="${NAME}" \
version="${NGINX_VERSION}-amd64-centos" \
maintainer="ignidis" \
help="For more information visit https://github.com/ignidis" \
usage="s2i build <SOURCE-REPOSITORY> ${NAME}:${NGINX_VERSION}-amd64-centos <APP-NAME>"
ARG NGINX_SVC_NAME
ARG NGINX_SVC_UID

#
# Add NGINX official repositories
Expand Down Expand Up @@ -100,6 +76,46 @@ RUN yum install -y yum-utils; \
ln -sf /dev/stdout /var/log/nginx/access.log; \
ln -sf /dev/stderr /var/log/nginx/error.log

#
# Compress the images
#
FROM scratch
COPY --from=0 / /

#
# Build Time Arguments
#
ARG NAME
ARG NGINX_VERSION
ARG NGINX_REPO
ARG NGINX_SHORT_REPO
ARG NGINX_SVC_NAME
ARG NGINX_SVC_UID

#
# Do some bookeeping for the repository and openshift
#
#
# It is deprecated but guess what...There are a lot of tools that still use it
#
MAINTAINER ignidis(at)cybearth(dot)net (https://github.com/ignidis/nginx-docker)

#
# And this is for those new tools
#
LABEL summary="Platform for running ${NAME}-${NGINX_SHORT_REPO}-${NGINX_VERSION} or building ${NAME}-based applications" \
description="${NAME} is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage. The container image provides a containerized packaging of the ${NAME}-${NGINX_SHORT_REPO}-$NGINX_VERSION daemon. The image can be used as a base image for other applications based on the ${NAME} web server. The ${NAME} server image can be extended using a source-to-image tool." \
io.k8s.description="${NAME} is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage. The container image provides a containerized packaging of the ${NAME}-${NGINX_SHORT_REPO}-$NGINX_VERSION daemon. The image can be used as a base image for other applications based on the ${NAME} web server. The ${NAME} server image can be extended using a source-to-image tool." \
io.k8s.display-name="NGINX-${NGINX_SHORT_REPO}-${NGINX_VERSION}" \
io.openshift.expose-services="8080:http" \
io.openshift.expose-services="8443:https" \
io.openshift.tags="builder,${NAME},${NAME}-${NGINX_SHORT_REPO}-${NGINX_VERSION}" \
name="${NAME}" \
version="${NGINX_VERSION}-amd64-centos" \
maintainer="ignidis(at)cybearth(dot)net" \
help="For more information visit https://github.com/ignidis/nginx-docker" \
usage="s2i build <SOURCE-REPOSITORY> ${NAME}:${NGINX_VERSION}-amd64-centos <APP-NAME>"

#
# Publish the standard web ports
#
Expand All @@ -109,4 +125,4 @@ STOPSIGNAL SIGTERM

USER ${NGINX_SVC_UID}

CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion stable/amd64/centos/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#
# Must run as superuser, either you are root or must sudo
#
docker build --build-arg NAME="nginx" --build-arg NGINX_VERSION="$1" --build-arg NGINX_REPO="nginx-stable" --build-arg NGINX_SHORT_REPO="stable" --build-arg NGINX_SVC_NAME="nginx" --build-arg NGINX_SVC_UID="9001" -t nginx:"$1"-amd64-centos .
docker build --build-arg NAME="NGINX" --build-arg NGINX_VERSION="$1" --build-arg NGINX_REPO="nginx-stable" --build-arg NGINX_SHORT_REPO="stable" --build-arg NGINX_SVC_NAME="nginx" --build-arg NGINX_SVC_UID="9001" -t nginx:"$1"-amd64-centos .

0 comments on commit bbf2e7d

Please sign in to comment.