diff --git a/serving/samples/helloworld-nodejs/Dockerfile b/serving/samples/helloworld-nodejs/Dockerfile index 50a9ec78c..ba0a6db49 100644 --- a/serving/samples/helloworld-nodejs/Dockerfile +++ b/serving/samples/helloworld-nodejs/Dockerfile @@ -1,17 +1,24 @@ +# Use the official Node 8 image. +# https://hub.docker.com/_/node FROM node:8 -# Create app directory +# Create and change to the app directory. WORKDIR /usr/src/app -# Install app dependencies -# A wildcard is used to ensure both package.json AND package-lock.json are copied -# where available (npm@5+) +# Copy application dependency manifests to the container image. +# A wildcard is used to ensure both package.json AND package-lock.json are copied. +# Copying this separately prevents re-running npm install on every code change. COPY package*.json ./ +# Install production dependencies. RUN npm install --only=production -# Bundle app source +# Copy local code to the container image. COPY . . -EXPOSE 8080 +# Configure and document the service HTTP port. +ENV PORT 8080 +EXPOSE $PORT + +# Run the web service on container startup. CMD [ "npm", "start" ] diff --git a/serving/samples/helloworld-nodejs/README.md b/serving/samples/helloworld-nodejs/README.md index 23062059d..64202de83 100644 --- a/serving/samples/helloworld-nodejs/README.md +++ b/serving/samples/helloworld-nodejs/README.md @@ -83,22 +83,29 @@ recreate the source files from this folder. see [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/). ```Dockerfile + # Use the official Node 8 image. + # https://hub.docker.com/_/node FROM node:8 - # Create app directory + # Create and change to the app directory. WORKDIR /usr/src/app - # Install app dependencies - # A wildcard is used to ensure both package.json AND package-lock.json are copied - # where available (npm@5+) + # Copy application dependency manifests to the container image. + # A wildcard is used to ensure both package.json AND package-lock.json are copied. + # Copying this separately prevents re-running npm install on every code change. COPY package*.json ./ + # Install production dependencies. RUN npm install --only=production - # Bundle app source + # Copy local code to the container image. COPY . . - EXPOSE 8080 + # Configure and document the service HTTP port. + ENV PORT 8080 + EXPOSE $PORT + + # Run the web service on container startup. CMD [ "npm", "start" ] ```