Dockerfile.vcsim 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Create a builder container
  2. # golang:1.18.0-buster amd64
  3. FROM golang@sha256:7d39537344486528f8cdb3bd8adb98ab7f0f4236044b6944fed8631da35a4ce5 AS build
  4. WORKDIR /go/src/app
  5. # Create appuser to isolate potential vulnerabilities
  6. # See https://stackoverflow.com/a/55757473/12429735
  7. ENV USER=appuser
  8. ENV UID=10001
  9. RUN adduser \
  10. --disabled-password \
  11. --gecos "" \
  12. --home "/nonexistent" \
  13. --shell "/sbin/nologin" \
  14. --no-create-home \
  15. --uid "${UID}" \
  16. "${USER}"
  17. # Create a new tmp directory so no bad actors can manipulate it
  18. RUN mkdir /temporary-tmp-directory && chmod 777 /temporary-tmp-directory
  19. ###############################################################################
  20. # Final stage
  21. FROM scratch
  22. # Run all commands as non-root
  23. USER appuser:appuser
  24. # Allow container to use latest TLS certificates
  25. COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
  26. # Copy over appuser to run as non-root
  27. COPY --from=build /etc/passwd /etc/passwd
  28. COPY --from=build /etc/group /etc/group
  29. # Copy over the /tmp directory for golang/os.TmpDir
  30. COPY --chown=appuser --from=build /temporary-tmp-directory /tmp
  31. # Expose application port
  32. EXPOSE 8989
  33. # Copy application from external build
  34. COPY vcsim /vcsim
  35. # Set entrypoint to application with container defaults
  36. ENTRYPOINT [ "/vcsim" ]
  37. CMD ["-l", "0.0.0.0:8989"]