博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
windows10 下docker部署nodejs
阅读量:6897 次
发布时间:2019-06-27

本文共 1795 字,大约阅读时间需要 5 分钟。

hot3.png

做完看见网上很多都都不熟nodejs到docker上运行:

 根据个人总结包含两种:一种是通过dockerFile直接打包成镜像进行运行;另一种则是挂在到docker镜像上进行运行。

今天讲解的是通过挂在nodejs项目到镜像上进行安装,首先我通过http://blog.shiqichan.com/Dockerizing-a-Node-js-Web-Application/ 该文进行nodejs镜像的下载:

PS C:\Users\hxf> docker run -it --rm node node --version

Unable to find image 'node:latest' locally
latest: Pulling from library/node

357ea8c3d80b: Pull complete

52befadefd24: Pull complete
3c0732d5313c: Pull complete
ceb711c7e301: Pull complete
868b1d0e2aad: Pull complete
61d10f626f84: Pull complete
Digest: sha256:12899eea666e85f23e9850bd3c309b1ee28dd0869f554a7a6895fc962d9094a3
Status: Downloaded newer image for node:latest
v6.4.0
PS C:\Users\hxf> docker run -it --rm node node --version
v6.4.0
PS C:\Users\hxf> git clone https://github.com/MarshalW/ProtoWebApp.git
Cloning into 'ProtoWebApp'...
remote: Counting objects: 44, done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 44 (delta 17), reused 44 (delta 17), pack-reused 0
Unpacking objects: 100% (44/44), done.
Checking connectivity... done.

进行到这一步,已经有nodejs镜像和nodejs项目,接下来就是进行nodejs的挂在和运行;

PS C:\Users\hxf\ProtoWebApp> docker run --rm -it -p 3000:3000 --name ProtoWebApp -v "$(pwd)":/webapp -w /webapp  node npm start

C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error parsing reference: ":/webapp" is not a valid repository/tag.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.

进行这一步报错,首先解释一下参数,

--rm 是指运行时加载到镜像,停止后,镜像中删除该应用

-p 是制定代理端口,

--name 制定应用id

-v 挂载本地目录,冒号后面是挂在镜像中的位置

-w 是工作目录

后面跟着的是运行命令。

对于错误原因,则是docker不能识别挂在的镜像,挂在的镜像必须是绝对路径,但是对于不识别的原因,寻找了一会,这是因为windows中的硬盘标识符需要共享出来,到docker setting中,把包含你项目运行的表示服共享出来,这样docker就可以认识了,此处有官方文档知道可以看看https://docs.docker.com/docker-for-windows/;

通过设置后再次运行该命令不报错,正常运行,并可以访问本地3000

出现需要的画面。

转载于:https://my.oschina.net/u/2497999/blog/738625

你可能感兴趣的文章
159. Longest Substring with At Most Two Distinct Characters
查看>>
利用PHP实现常用的数据结构之二叉树(小白系列文章五)
查看>>
Intellij Idea + spring-boot + thymleaf实现热部署
查看>>
js--string/正则表达式replace方法详解
查看>>
基于Vue2实现的仿手机QQapp(支持对话功能,滑动删除....)—— 聊聊开发过程中踩到的一些坑与解决方案,以及个人感悟...
查看>>
(三)java多线程之wait notify notifyAll
查看>>
[面经] [实习] Next Capital 实习 Summer 2017 OA
查看>>
那家CTO带头喊麦的直播公司,快要倒闭了
查看>>
想像亚马逊或 Netflix 一样酷?抱走敏捷转型五大秘籍
查看>>
揭秘码云:全球第二大代码托管平台的核心架构
查看>>
V8十年故事:从农场诞生的星球最强JS引擎
查看>>
AI一周热闻:周志华获IEEE技术成就奖;英伟达发布最小AI计算机
查看>>
有赞透明多级缓存解决方案(TMC)设计思路
查看>>
使用Prometheus和Grafana实现SLO
查看>>
堆和栈
查看>>
Spotify希望自己擅于失败
查看>>
隐私和安全是macOS Mojave和Safari 12的第一要务
查看>>
《Agendashift》的作者访谈录(一)
查看>>
Kong 发布 Kong Brain 和 Kong Immunity,可进行智能自动化和适应性监控
查看>>
面试时,面试官到底在考察什么?
查看>>