您现在的位置是:热点 >>正文
云计算核心技术Docker教程:将 Node.js 的镜像作为容器运行
热点09192人已围观
简介...
容器是一个普通的操作系统进程,只是这个进程是隔离的,有自己的文件系统,自己的网络,以及与主机分离的自己的隔离进程树。
要在容器内运行映像,我们使用该docker run命令。该d云计ocker run命令需要一个参数,即图像名称。让我们启动我们的图像并确保它正确运行。在终端中执行以下命令。
$ docker run node-docker
当您运行此命令时,您会注意算核到您没有返回到命令提示符。这是因为我们的应用程序是一个 REST 服务器,它将在循环中运行,等待传入的请求,而不会将控制权返回给操作系统,直到我们停止容器。
让我们打开一个新终端,然后使心技用 curl 命令向服务器发出 GET 请求。
$ curl --request POST \
--url http://localhost:8000/test \
--header 'content-t术Dype: 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 --pu将 blish 8000:8000 node-docker
现在让我们从上面重新运行 curl 命令。记得打开一个新的终端。
$ curl --request POST \
--url http://localNohost:8000/test \
--header 'content-type: application/json' \
--data '{"msg": "testing"}'
de3;"code":"success","payload":[{"msg":"testing","id":"dc0e2c2b-793d-433c-8645-b3a553ea26.jde","createDate":"2020-09-01T17:36:09.897Z"}]}
成功!我们能够在端口 8000 上连接到在容器内运行的应用程序。切换回运行容器的终端,您s 应该会看到 POST 请求记录到控制台。
2020-09-01T17:36:09:8770 INFO: POST /test
按 ctrl-c 停止容器。
Tags:
相关文章
标签: 厨电行业
热点撰文 | 曹双涛 编辑 | 杨博丞 题图 | 豆包AI 2026年,国内集成灶行业比以往任何时候都需要一场彻底的“自救”。 地产周期波动引发的市场需求持续萎缩、人力与渠道成本高企、产品同质化加剧价格战...
【热点】
阅读更多云计算核心技术Docker教程:注册服务器开放外部访问
热点运行只能访问的注册表的localhost用处有限。为了使外部主机可以访问您的注册表,您必须首先使用 TLS 保护它。 获得证书 这些示例假设如下: 您的注册表 URL 是https://myregis...
【热点】
阅读更多亚马逊云科技re:Inforce 2023强调安全服务的AI赋能
热点6月19日消息,在近日的亚马逊云科技 re:Inforce 2023全球大会上,亚马逊云科技推出十多项安全新服务及功能,包括 Amazon Verified Permissions 正式可用、扩展 A...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.swanagerailway.co.uk/search?q=蜘蛛池出租【tg:seogoogle987】,giX
- https://www.flickr.com/photos/tags/蜘蛛池出租【tg:seogoogle987】R94
- https://www.teamlab.art/?submit=蜘蛛池出租【tg:seogoogle987】,dmT
- https://www.unclefossil.com/search/蜘蛛池出租【tg:seogoogle987】gad_source=1&gclid=Cj0KCQjw_-GxBhC1ARIsADGgDjsNKplUXa2F6YGlHBK2sHDQ88cgsJBb05DyO99TV9jNq_cT0kGMqyQaAgHQEALw_wcB
- https://www.ons.gov.uk/search?q=蜘蛛池出租【tg:seogoogle987】,N1g
- https://www.soccerbible.com/search?q=蜘蛛池出租【tg:seogoogle987】,ntQ
- https://www.lauben.com/de/?s=蜘蛛池出租【tg:seogoogle987】,dJX
- https://www.xvideos.com/tags/蜘蛛池出租【tg:seogoogle987】,IAB
- https://www.theaerogroup.net/?cat=28&s=蜘蛛池出租【tg:seogoogle987】,PPO
- https://www.seagrant.wisc.edu/?page=63&s=蜘蛛池出租【tg:seogoogle987】,Tna
- https://www.mesec.cz/vyhledavani/?qs=蜘蛛池出租【tg:seogoogle987】,n2r
- https://www.silentiumpc.com/en/search/蜘蛛池出租【tg:seogoogle987】,1tY
- https://www.springfieldlibrary.org/library/?s=蜘蛛池出租【tg:seogoogle987】,Zya
- https://www.remit.co.jp/pt/?action=CHECK&s=蜘蛛池出租【tg:seogoogle987】,OqS
- https://www.wheels24.gr/?action=CHECK&s=蜘蛛池出租【tg:seogoogle987】,ggq
- https://www.signingsavvy.com/sentence/蜘蛛池出租【tg:seogoogle987】,G1i
- https://www.repetto.jp/item/search?action=QUERY&q=蜘蛛池出租【tg:seogoogle987】,PZu
- https://www.kaiyueleather.com/search/蜘蛛池出租【tg:seogoogle987】,XGi
- https://www.youthforum.org/search-results?cx=4f5236218ab5e8ef9&ie=UTF-8&q=蜘蛛池出租【tg:seogoogle987】,aBg
- https://www.wellbees.com/catalogsearch/result/?action=CHECK&q=蜘蛛池出租【tg:seogoogle987】,Me6
- https://www.paxnet.co.kr/search/jongmok?kwd=蜘蛛池出租【tg:seogoogle987】YdF
- https://www.mingwai.edu.hk/?langzh-hant&s=蜘蛛池出租【tg:seogoogle987】,L8U
- https://www.temu.com/search_result.html?search_key=蜘蛛池出租【tg:seogoogle987】DJk
- https://www.zutari.com/search/蜘蛛池出租【tg:seogoogle987】,qQq
- https://www.ng-slo.si/si/iskanje?cat=114&q=蜘蛛池出租【tg:seogoogle987】,Pww
- https://www.impactpool.org/search/?type=79&q=蜘蛛池出租【tg:seogoogle987】7j2
- https://www.jusoen.com/addreng.asp?p1=蜘蛛池出租【tg:seogoogle987】xGp
- https://www.roberthalf.com/us/en/jobs/all/蜘蛛池出租【tg:seogoogle987】V8K
- https://www.smarty.net/search?q=蜘蛛池出租【tg:seogoogle987】,dXn
- https://www.routesonline.com/search/?query=蜘蛛池出租【tg:seogoogle987】,DiA
- https://www.schenckprocess.com/search?q=蜘蛛池出租【tg:seogoogle987】,WCw
- https://www.roberthalf.com/us/en/jobs/all/蜘蛛池出租【tg:seogoogle987】M26
- https://www.monroecounty.gov/search/?q=蜘蛛池出租【tg:seogoogle987】,00u
- https://www.paulaschoice.hk/zh_hant/catalogsearch/result/?q=蜘蛛池出租【tg:seogoogle987】,5KA
- https://www.duksung.ac.kr/search/front/Search.jsp?qt=蜘蛛池出租【tg:seogoogle987】r2H
- https://www.polliwogs.com/search/蜘蛛池出租【tg:seogoogle987】,nLS
- https://www.metaltix.com/?view=tours&filter=search&q=蜘蛛池出租【tg:seogoogle987】,8SR
- https://www.jusoen.com/addreng.asp?p1=蜘蛛池出租【tg:seogoogle987】mly
- https://www.vocabulary.com/dictionary/蜘蛛池出租【tg:seogoogle987】,7aY
- https://www.yli.ro/catalogsearch/result/?q=蜘蛛池出租【tg:seogoogle987】,MjQ
- https://www.symatoys.com/search.html?ID=UyMD6aO58bPrJvQAB1I0N69KzJBZeNPC&keyword=蜘蛛池出租【tg:seogoogle987】,vDi
- https://www.remit.co.jp/ne/?s=蜘蛛池出租【tg:seogoogle987】,Fnj
- https://blvdseafood.com/?s=蜘蛛池出租【tg:seogoogle987】acY
- https://www.lechzuers.com/de/search?cat=163&q=蜘蛛池出租【tg:seogoogle987】,NSC
- https://www.miamiopenmri.com/?action=CHECK&s=蜘蛛池出租【tg:seogoogle987】,jeX
- https://www.losgatoschamber.com/list/search?action=SEARCH&q=蜘蛛池出租【tg:seogoogle987】,4z6
- https://www.universal-music.co.jp/?ID=1sIcckCTeBS8FjzCshAW9w53s8gr691o&s=蜘蛛池出租【tg:seogoogle987】,GXN
- https://www.wmfe.org/?s=蜘蛛池出租【tg:seogoogle987】,Gts
- https://www.teacherspayteachers.com/Browse/Search:蜘蛛池出租【tg:seogoogle987】,M8o
- https://www.uctronics.com/catalogsearch/result/?q=蜘蛛池出租【tg:seogoogle987】,v1Q