nodejs Docker image

nodejs.Dockerfile

The nodejs.Dockerfile creates a production Docker image, which:

  1. Uses the tiny Node 14 Alpine Docker Hub image as a base.
  2. Sets environment variables, including NODE_ENV=development and NODE_ENV=production for development and production respectively.
  3. Creates a working directory (/home/node/app) and grants access to the node user.
  4. Copies package.json and installs modules.
  5. Copies the remaining application files.
  6. Runs the build script. This creates a static directory for client-side files and is mounted as a Docker volume and shared with other containers.
  7. Exposes port 8000.
  8. Runs the Express.js application (index.js).

Get hands-on with 1400+ tech skills courses.