您现在的位置是:热点 >>正文
云计算核心技术Docker教程:将 Node.js 的镜像作为容器运行
热点3615人已围观
简介...
容器是一个普通的操作系统进程,只是这个进程是隔离的,有自己的文件系统,自己的网络,以及与主机分离的自己的隔离进程树。
要在容器内运行映像,我们使用该docker run命令。该d云计ocker run命令需要一个参数,即图像名称。让我们启动我们的图像并确保它正确运行。在终端中执行以下命令。
$ docker run node-docker
当您运行此命令时,您会注意到您没有返算核回到命令提示符。这是因为我们的应用程序是一个 REST 服务器,它将在循环中运行,等待传入的请求,而不会将控制权返回给操作系统,直到我们停止容器。
让我们打开一个新终端,然后使用 c心技url 命令向服务器发出 GET 请求。
$ curl --request POST \
--url http://localhost:8000/test \
--header 'content-ty术Dpe: application/json' \
--data '{"msg": "testing"}'
curl: (7) Failed to connect to localhost port 8oc000: Connection refused
我们的 curl 命令失败,因为与我们的服务器的连接被拒绝。这意味着我们无法在端口 8000 上连接到 localhost。这是意料之中的,因为ke我们的容器是独立运行的,包括网络。让我们停止容器并使用我们本地网络上发布的端口 8000 重新启动。
要停止容器,请按 ctrl-c。这将使您返回到终端提示。
要为我们的容器发布端口,我r教们将在 docker run 命令上使用--publish标志(-p简称)。--publish命令的格式为[host port]:[container port]. 因此,如果我们想将容器内程:的端口 8000 暴露给容器外的端口 3000,我们会将 3000:8000 传递给 --publish 标志。
启动容器并将端口 8000 暴露给主机上的端口 8000。
$ docker run --pub将 lish 8000:8000 node-docker
现在让我们从上面重新运行 curl 命令。记得打开一个新的终端。
$ curl --request POST \
--url http://loNocalhost:8000/test \
--header 'content-type: application/json' \
--data '{"msg": "testing"}'
&de#123;"code":"success","payload":[{"msg":"testing","id":"dc0e2c2b-793d-433c-8645-b3a553e.ja26de","createDate":"2020-09-01T17:36:09.897Z"}]}
成功!我们能够在端口 8000 上连接到在容器内运行的应用程序。切换回运行容器的s 终端,您应该会看到 POST 请求记录到控制台。
2020-09-01T17:36:09:8770 INFO: POST /test
按 ctrl-c 停止容器。
Tags:
相关文章
分析师称苹果造车或面临挑战:高投入低回报
热点据报道,本周一,外媒报道称苹果有可能将在2024年开始生产电动汽车,新车将使用苹果自己研发的电池技术。这个报道重燃了外界对苹果汽车业务的兴趣,2015年的时候,媒体首次报道称苹果有意进军汽车行业,但是...
【热点】
阅读更多桑葚是碱性还是酸性
热点哪些食物含碱性多?E.属于热性的碱性食物有:大蒜、辣椒、胡椒意见建议:水果类碱性食物大全A.属于寒性的碱性食物有:猕猴桃、柿子、桑葚、无花果、甘蔗、香蕉、荸。桑葚属性?桑葚属于碱性食材。食物的酸碱性不...
【热点】
阅读更多标签: 美团 钱江摩托 OTA锁电 AcFun
热点Hello,大家早上好,又是元气满满的一天,先来浏览新鲜的早报吧~ 【平台取消超时扣款】 美团、淘宝闪购、淘宝天猫、京东、滴滴、高德、T3、百度、满帮、货拉拉、拼多多、抖音、携程、去哪儿网等平台积极响...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.pearson.com/en-us/search.html?aq=谷歌留痕软件【tg:seogoogle987】,F7e
- https://www.sonepar.ch/fr/search?q=谷歌留痕软件【tg:seogoogle987】,0E3
- https://www.merchbar.com/search?q=谷歌留痕软件【tg:seogoogle987】,4Xe
- https://www.tiktok.com/tag/谷歌留痕软件【tg:seogoogle987】,LGf
- https://www.stormberg.com/no/search?q=谷歌留痕软件【tg:seogoogle987】,53F
- https://www.impactpool.org/search/?type=79&q=谷歌留痕软件【tg:seogoogle987】1BF
- https://www.mingwai.edu.hk/?langzh-hant&s=谷歌留痕软件【tg:seogoogle987】,Vn2
- https://www.parl.ca/legisinfo/fr/projets-de-loi?parlsession=all&view=list&keywords=谷歌留痕软件【tg:seogoogle987】,AIu
- https://www.tmtpost.com/search?q=谷歌留痕软件【tg:seogoogle987】,huk
- https://www.zalora.sg/catalog/?cat=112&q=谷歌留痕软件【tg:seogoogle987】,I1v
- https://www.tumblr.com/tagged/谷歌留痕软件【tg:seogoogle987】,kPx
- https://www.wuv.edu/?s=谷歌留痕软件【tg:seogoogle987】,nhs
- https://www.ntv.co.jp/3min/search/?action=QUERY&q=谷歌留痕软件【tg:seogoogle987】,52J
- https://www.pixiv.net/tags/谷歌留痕软件【tg:seogoogle987】,FED
- https://www.xvideos.com/tags/谷歌留痕软件【tg:seogoogle987】,KW3
- https://www.lee.com/search?q=谷歌留痕软件【tg:seogoogle987】,Kh1
- https://www.spicebar.de/catalogsearch/result/?q=谷歌留痕软件【tg:seogoogle987】,AKD
- https://www.roblox.com/discover/?cat=107&Keyword=谷歌留痕软件【tg:seogoogle987】,FKT
- https://www.rookwinkel.nl/catalogsearch/result/index/?q=谷歌留痕软件【tg:seogoogle987】,ofO
- https://www.temu.com/search_result.html?search_key=谷歌留痕软件【tg:seogoogle987】kUs
- https://www.military-history.org/?s=谷歌留痕软件【tg:seogoogle987】,LRo
- https://www.youthforum.org/search-results?cx=4f5236218ab5e8ef9&ie=UTF-8&q=谷歌留痕软件【tg:seogoogle987】,HDB
- https://www.jusoen.com/addreng.asp?p1=谷歌留痕软件【tg:seogoogle987】hvw
- https://www.randjleather.co.uk/index.php?route=product/search&tag=谷歌留痕软件【tg:seogoogle987】,dID
- https://www.wilsonart.com/catalogsearch/result/?action=CHECK&q=谷歌留痕软件【tg:seogoogle987】,6L8
- https://www.whirlpool.com.hk/chinese/catalogsearch/result?cat=30&q=谷歌留痕软件【tg:seogoogle987】,OKX
- https://www.jusoen.com/addreng.asp?p1=谷歌留痕软件【tg:seogoogle987】ryu
- https://www.realsporting.com/buscador?buscar=谷歌留痕软件【tg:seogoogle987】,oF9
- https://www.kubb-tool.bfs.admin.ch/en/search?action=CHECK&q=谷歌留痕软件【tg:seogoogle987】,aXH
- https://www.safetv.go.kr/base/search/view?searchWord=谷歌留痕软件【tg:seogoogle987】qcb
- https://www.lifesciencesweden.se/search?q=谷歌留痕软件【tg:seogoogle987】,olE
- https://www.woorden.org/spreekwoord.php?woord=谷歌留痕软件【tg:seogoogle987】,qtB
- https://yscc1986.net/search/谷歌留痕软件【tg:seogoogle987】DUG
- https://www.remit.co.jp/id/?s=谷歌留痕软件【tg:seogoogle987】,uYo
- https://blvdseafood.com/?s=谷歌留痕软件【tg:seogoogle987】yES
- https://www.sensorshop24.de/catalogsearch/result/index/?type=132&q=谷歌留痕软件【tg:seogoogle987】,NCz
- https://www.zisha.com/shop/list.shtml?wap_keyword=谷歌留痕软件【tg:seogoogle987】,Lh0
- https://www.varian.com/en-au/search?cat=113&search=谷歌留痕软件【tg:seogoogle987】,SPb
- https://www.sbaad.no/?s=谷歌留痕软件【tg:seogoogle987】,135
- https://www.thedp.com/page/search?q=谷歌留痕软件【tg:seogoogle987】,te7
- https://www.kawainter.com/catalogsearch/result/?q=谷歌留痕软件【tg:seogoogle987】,Nnf
- https://www.kuaikanmanhua.com/sou/谷歌留痕软件【tg:seogoogle987】,FOA
- https://www.therapeuticassociates.com/?cat=5&s=谷歌留痕软件【tg:seogoogle987】,CgN
- https://www.riohondo.edu/?action=QUERY&s=谷歌留痕软件【tg:seogoogle987】,It2
- https://www.smarty.net/search?q=谷歌留痕软件【tg:seogoogle987】,kpm
- https://www.unclefossil.com/search/谷歌留痕软件【tg:seogoogle987】,YKa
- https://www.revere.org/search?action=SEARCH&q=谷歌留痕软件【tg:seogoogle987】,3Zk
- https://www.remit.co.jp/zh/?s=谷歌留痕软件【tg:seogoogle987】,iMu
- https://hsmoa.com/search?query=谷歌留痕软件【tg:seogoogle987】VBA
- https://www.rea.govt.nz/search?searchterm=谷歌留痕软件【tg:seogoogle987】,tBu