1. 获取镜像

  1. # 查看可用的稳定版本
  2. sudo docker search node
  3. sudo docker pull kkarczmarczyk/node-yarn
  4. sudo docker image ls |grep node

2. 创建数据卷

  1. sudo mkdir -p /share/node/app

3. 启动容器

  1. sudo docker run -it --name nodeapp -v /share/node/app/:/workspace -p 80:80 kkarczmarczyk/node-yarn
  2. # 退出容器(Ctrl + P + Q)
  3. sudo docker start nodeapp
  4. sudo docker restart nodeapp
  5. sudo docker stop nodeapp
  6. sudo docker rm nodeapp

4. 验证

  1. # 进入终端
  2. sudo docker exec -it nodeapp /bin/bash
  3. # 安装vue-cli
  4. yarn global add @vue/cli
  5. # 编译项目
  6. yarn
  7. # 启动项目
  8. yarn serve
  9. # 查看日志
  10. sudo docker logs nodeapp
  11. sudo docker logs -f -t --tail=50 nodeapp
  12. # 查看网络
  13. sudo docker network ls
  14. sudo docker inspect nodeapp