Project Solution: Docker Images
The images used in Dockerfiles and the Compose file are discussed in this lesson.
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.
Ask