Dockerfile.alpine 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # setup build arguments for version of dependencies to use
  2. ARG DOCKER_GEN_VERSION=0.7.6
  3. ARG FOREGO_VERSION=v0.17.0
  4. # Use a specific version of golang to build both binaries
  5. FROM golang:1.16.5-alpine as gobuilder
  6. RUN apk add --no-cache git musl-dev
  7. # Build docker-gen from scratch
  8. FROM gobuilder as dockergen
  9. ARG DOCKER_GEN_VERSION
  10. RUN git clone https://github.com/jwilder/docker-gen \
  11. && cd /go/docker-gen \
  12. && git -c advice.detachedHead=false checkout $DOCKER_GEN_VERSION \
  13. && go mod download \
  14. && CGO_ENABLED=0 go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen \
  15. && go clean -cache \
  16. && mv docker-gen /usr/local/bin/ \
  17. && cd - \
  18. && rm -rf /go/docker-gen
  19. # Build forego from scratch
  20. FROM gobuilder as forego
  21. ARG FOREGO_VERSION
  22. RUN git clone https://github.com/nginx-proxy/forego/ \
  23. && cd /go/forego \
  24. && git -c advice.detachedHead=false checkout $FOREGO_VERSION \
  25. && go mod download \
  26. && CGO_ENABLED=0 go build -o forego . \
  27. && go clean -cache \
  28. && mv forego /usr/local/bin/ \
  29. && cd - \
  30. && rm -rf /go/forego
  31. # Build the final image
  32. FROM nginx:1.19.10-alpine
  33. LABEL maintainer="Nicolas Duchon <nicolas.duchon@gmail.com> (@buchdag)"
  34. # Install wget and install/updates certificates
  35. RUN apk add --no-cache --virtual .run-deps \
  36. ca-certificates bash wget openssl \
  37. && update-ca-certificates
  38. # Configure Nginx and apply fix for very long server names
  39. RUN echo "daemon off;" >> /etc/nginx/nginx.conf \
  40. && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \
  41. && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf
  42. # Install Forego + docker-gen
  43. COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego
  44. COPY --from=dockergen /usr/local/bin/docker-gen /usr/local/bin/docker-gen
  45. # Add DOCKER_GEN_VERSION environment variable
  46. # Because some external projects rely on it
  47. ARG DOCKER_GEN_VERSION
  48. ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION}
  49. COPY network_internal.conf /etc/nginx/
  50. COPY . /app/
  51. WORKDIR /app/
  52. ENV DOCKER_HOST unix:///tmp/docker.sock
  53. VOLUME ["/etc/nginx/certs", "/etc/nginx/dhparam"]
  54. ENTRYPOINT ["/app/docker-entrypoint.sh"]
  55. CMD ["forego", "start", "-r"]