Project Solution: Docker Images
Explore how to create and manage Docker images for a Node.js quiz app using Alpine-based Node.js and NGINX images, along with MongoDB. Learn to set environment variables, mount volumes for live editing, configure NGINX for request routing, and use production-ready Docker Compose setups with restart policies and internal port exposure.
nodejs Docker image
nodejs.Dockerfile
The nodejs.Dockerfile creates a production Docker image, which:
- Uses the tiny Node 14 Alpine Docker Hub image as a base.
- Sets environment variables, including
NODE_ENV=developmentandNODE_ENV=productionfor development and production respectively. - Creates a working directory (
/home/node/app) and grants access to thenodeuser. - Copies
package.jsonand installs modules. - Copies the remaining application files.
- Runs the build script. This creates a
staticdirectory for client-side files and is mounted as a Docker volume and shared with other containers. - Exposes port
8000.