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=development
andNODE_ENV=production
for development and production respectively. - Creates a working directory (
/home/node/app
) and grants access to thenode
user. - Copies
package.json
and installs modules. - Copies the remaining application files.
- 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. - Exposes port
8000
. - Runs the Express.js application (
index.js
).
Get hands-on with 1400+ tech skills courses.