Dockerfile 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # ---------------------------------------------------
  2. # Build Stage
  3. # ---------------------------------------------------
  4. # Use Alpine Linux 3.18 as the base image for the build stage
  5. FROM alpine:3.18 AS build
  6. # Update package list and install build dependencies
  7. RUN apk update && \
  8. apk add --no-cache \
  9. build-base zlib-dev
  10. # Set the working directory inside the container
  11. WORKDIR /civetweb
  12. # Copy source code and other necessary files into the container
  13. COPY src ./src/
  14. COPY include ./include/
  15. COPY Makefile ./
  16. COPY resources ./resources/
  17. COPY *.md ./
  18. # Build Civetweb with all features and install it into /app directory
  19. RUN make build && \
  20. make WITH_ALL=1 && \
  21. make install PREFIX=/app
  22. # ---------------------------------------------------
  23. # Image Stage
  24. # ---------------------------------------------------
  25. # Use Alpine Linux 3.18 as the base image for the final stage
  26. FROM alpine:3.18
  27. # Update package list and install runtime dependencies
  28. RUN apk update && \
  29. apk add --no-cache \
  30. libstdc++ zlib
  31. # Create a non-root user and group for running Civetweb
  32. RUN addgroup -S civetweb && adduser -S civetweb -G civetweb
  33. # Switch to the non-root user
  34. USER civetweb
  35. # Copy the built application from the build stage into this stage
  36. COPY --chown=civetweb:civetweb --from=build /app/ /app/
  37. # Expose port 8080 for the application
  38. EXPOSE 8080
  39. # Set the entry point for the container
  40. ENTRYPOINT [ "/app/bin/civetweb", "/app/etc/civetweb.conf" ]