mirror of https://github.com/knative/docs.git
serving/samples/helloworld-nodejs: simplify and standardize Dockerfile (#507)
This commit is contained in:
parent
f2518ca45b
commit
ab11b92622
|
@ -1,17 +1,24 @@
|
||||||
|
# Use the official Node 8 image.
|
||||||
|
# https://hub.docker.com/_/node
|
||||||
FROM node:8
|
FROM node:8
|
||||||
|
|
||||||
# Create app directory
|
# Create and change to the app directory.
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Install app dependencies
|
# Copy application dependency manifests to the container image.
|
||||||
# A wildcard is used to ensure both package.json AND package-lock.json are copied
|
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
|
||||||
# where available (npm@5+)
|
# Copying this separately prevents re-running npm install on every code change.
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install production dependencies.
|
||||||
RUN npm install --only=production
|
RUN npm install --only=production
|
||||||
|
|
||||||
# Bundle app source
|
# Copy local code to the container image.
|
||||||
COPY . .
|
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" ]
|
CMD [ "npm", "start" ]
|
||||||
|
|
|
@ -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/).
|
see [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/).
|
||||||
|
|
||||||
```Dockerfile
|
```Dockerfile
|
||||||
|
# Use the official Node 8 image.
|
||||||
|
# https://hub.docker.com/_/node
|
||||||
FROM node:8
|
FROM node:8
|
||||||
|
|
||||||
# Create app directory
|
# Create and change to the app directory.
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Install app dependencies
|
# Copy application dependency manifests to the container image.
|
||||||
# A wildcard is used to ensure both package.json AND package-lock.json are copied
|
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
|
||||||
# where available (npm@5+)
|
# Copying this separately prevents re-running npm install on every code change.
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install production dependencies.
|
||||||
RUN npm install --only=production
|
RUN npm install --only=production
|
||||||
|
|
||||||
# Bundle app source
|
# Copy local code to the container image.
|
||||||
COPY . .
|
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" ]
|
CMD [ "npm", "start" ]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue