1
0
Fork 0
mirror of https://github.com/nginx-proxy/nginx-proxy synced 2024-05-27 09:56:17 +02:00
nginx-proxy/Dockerfile

78 lines
2.3 KiB
Docker
Raw Normal View History

# setup build arguments for version of dependencies to use
ARG DOCKER_GEN_VERSION=0.7.6
ARG FOREGO_VERSION=0.16.1
# Use a specific version of golang to build both binaries
FROM golang:1.15.10 as gobuilder
# Build docker-gen from scratch
FROM gobuilder as dockergen
ARG DOCKER_GEN_VERSION
RUN git clone https://github.com/jwilder/docker-gen \
&& cd /go/docker-gen \
&& git -c advice.detachedHead=false checkout $DOCKER_GEN_VERSION \
&& go mod download \
&& CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen \
&& go clean -cache \
&& mv docker-gen /usr/local/bin/ \
&& cd - \
&& rm -rf /go/docker-gen
# Build forego from scratch
# Because this relies on golang workspaces, we need to use go < 1.8.
FROM gobuilder as forego
# Download the sources for the given version
ARG FOREGO_VERSION
ADD https://github.com/jwilder/forego/archive/v${FOREGO_VERSION}.tar.gz sources.tar.gz
# Move the sources into the right directory
RUN tar -xzf sources.tar.gz && \
mkdir -p /go/src/github.com/ddollar/ && \
mv forego-* /go/src/github.com/ddollar/forego
# Install the dependencies and make the forego executable
WORKDIR /go/src/github.com/ddollar/forego/
RUN go get -v ./... && \
CGO_ENABLED=0 GOOS=linux go build -o forego .
# Build the final image
FROM nginx:1.19.3
LABEL maintainer="Nicolas Duchon <nicolas.duchon@gmail.com> (@buchdag)"
2014-05-05 18:59:23 +02:00
# Install wget and install/updates certificates
RUN apt-get update \
&& apt-get install -y -q --no-install-recommends \
ca-certificates \
wget \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/*
# Configure Nginx and apply fix for very long server names
RUN echo "daemon off;" >> /etc/nginx/nginx.conf \
2017-06-12 09:59:55 +02:00
&& sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf
# Install Forego + docker-gen
COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego
COPY --from=dockergen /usr/local/bin/docker-gen /usr/local/bin/docker-gen
2014-06-07 21:53:16 +02:00
# Add DOCKER_GEN_VERSION environment variable
# Because some external projects rely on it
ARG DOCKER_GEN_VERSION
ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION}
COPY network_internal.conf /etc/nginx/
COPY . /app/
WORKDIR /app/
2014-05-05 18:59:23 +02:00
ENV DOCKER_HOST unix:///tmp/docker.sock
VOLUME ["/etc/nginx/certs", "/etc/nginx/dhparam"]
Add SSL support This adds SSL support for containers. It supports single host certificates, wildcards and SNI using naming conventions for certificates or optionally specify a cert name (for SNI). The SSL cipher configuration is based on mozilla intermediate profile which should provide compatibility with clients back to Firefox 1, Chrome 1, IE 7, Opera 5, Safari 1, Windows XP IE8, Android 2.3, Java 7. The configuration also enables OCSP stapling, HSTS, and ssl session caches. To enable SSL, nginx-proxy should be started w/ -p 443:443 and -v /path/to/certs:/etc/nginx/certs. Certificates must be named: <virtualhost>.crt and <virtualhost>.key where <virtualhost> matches the a value of VIRTUAL_HOST on a container. For wildcard certificates, the certificate and private key should be named after the wildcard domain with .crt and .key suffixes. For example, *.example.com should be name example.com.crt and example.com.key. For SNI where a certificate may be used for multiple domain names, the container can specify a CERT_NAME env var that corresponds to the base file name of the certificate and key. For example, if you have a cert allowing *.example.com and *.bar.com, it can be name shared.crt and shared.key. A container can use that cert by having CERT_NAME=shared and VIRTUAL_HOST=foo.example.com. The name "shared" is arbitrary and can be whatever makes sense. The behavior for the proxy when port 80 and 443 is defined is as follows: * If a container has a usable cert, port 80 will redirect to 443 for that container to always prefer HTTPS when available. * If the container does not have a usable cert 503 will be returned. In the last case, a self-signed or generic cert can be defined as "default.crt" and "default.key" which will allow a client browser to at least make a SSL connection.
2014-11-26 18:38:51 +01:00
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["forego", "start", "-r"]