Docker:how to build image

files

hello-world/
├── Dockerfile
├── index.js
├── package.json

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
FROM node:8-alpine

# Create app directory
WORKDIR /home/hello-world

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm install --only=production

# Bundle app source
COPY . .

EXPOSE 8080
CMD [ "npm", "start" ]

ref:https://nodejs.org/en/docs/guides/nodejs-docker-webapp/

index.js

server.js

build

1
sudo docker build -t liuliaixue/nodejs-hello-world .