DEV Community

Kevan Y
Kevan Y

Posted on

3 2

Release 2.9

My Work

Apply Dockerfile best practices from Snyk recommendations #1668
List of Dockerfile worked:

In overall it was pretty straightforward once one of the PR got reviewed, and I can use it as a template.

One of the process steps

References
Image description

  • For the image version we need to use an image to a specific version(Not using alpine version for package installation since M1 required more tools to work)
 - FROM node:lts as base
 + FROM node:16 as base
Enter fullscreen mode Exit fullscreen mode
  • Setup multi staging
 + FROM node:16 as base
 + FROM base as dependencies
 + FROM node:16-alpine3.15 as deploy
Enter fullscreen mode Exit fullscreen mode

Base stage is for installing the tool needed for package installation.
Dependencies stage is for installing node_modules.
Deploy stage is where we copy sources code from the build context and node_modules from Dependencies and run our services.

  • Run node app as node user
+ COPY --chown=node:node . .
+ USER node
Enter fullscreen mode Exit fullscreen mode

This allows Node user to have permission to read our sources code.

  • Add a healthcheck
+ ENV PORT
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
+   CMD wget --no-verbose --tries=1 --spider localhost:${DEPENDENCY_DISCOVERY_PORT}/healthcheck || exit 1
Enter fullscreen mode Exit fullscreen mode

This is the change I made, one thing @humphd noticed building the application with a node-alpine image, on ARM architecture, it's required to use a bigger node image to be able to build it. See PR 3336

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay