1. mkdir nodejs
    2. cd nodejs
    3. npm init -y // 初始化项目
    4. npm i koa -S // 安装KOA

    项目中添加APP.js文件

    1. const Koa = require('koa')
    2. const app = new Koa()
    3. app.use(ctx => {
    4. ctx.body = "Hello nodejs in Docker"
    5. })
    6. app.listen(3000, () => {
    7. console.log('app started at port 3000')
    8. })

    添加Dockerfile文件

    1. FROM node:10-alpine
    2. ADD . /app/
    3. WORKDIR /app
    4. RUN npm install
    5. EXPOSE 3000
    6. CMD ["node", "app.js"]

    构建和启动

    1. docker build -t mynode .
    2. docker run -p 3000:3000 mynode