本篇內(nèi)容介紹了“如何制作多端口httpserver的容器鏡像”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
站在用戶(hù)的角度思考問(wèn)題,與客戶(hù)深入溝通,找到英吉沙網(wǎng)站設(shè)計(jì)與英吉沙網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶(hù)體驗(yàn)好的作品,建站類(lèi)型包括:網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋英吉沙地區(qū)。
創(chuàng)建/root/myapp目錄
[root@xbldockerbuild myapp]# tree /root/myapp /root/myapp ├── Dockerfile └── src └── app.js 1 directory, 2 files
其中app.js和Dockerfile 內(nèi)容如下
[root@xbldockerbuild myapp]# cat src/app.js var http=require('http'); var ports = [7006, 7007, 7008, 7009]; var servers = []; var s; function reqHandler(req, res) { var serPort=req.socket.localPort; res.writeHead(200, {'Content-Type':'text/plain'}); res.write('Listening on port ' + serPort); res.end(); } ports.forEach(function(port) { s = http.createServer(reqHandler); s.listen(port); servers.push(s); });
[root@xbldockerbuild myapp]# cat Dockerfile FROM alpine:3.8 RUN apk update RUN apk add --no-cache nodejs COPY ./src /app CMD ["/usr/bin/node", "/app/app.js"] EXPOSE 7006/tcp EXPOSE 7007/tcp EXPOSE 7008/tcp EXPOSE 7009/tcp
docker build 制作容器鏡像
[root@xbldockerbuild myapp]# docker build -t alpine-node-multiple-ports:v1 . Sending build context to Docker daemon 3.584 kB Step 1/9 : FROM alpine:3.8 ---> dac705114996 Step 2/9 : RUN apk update ---> Using cache ---> a822afa9e3ed Step 3/9 : RUN apk add --no-cache nodejs ---> Using cache ---> 325de7d2e3a6 Step 4/9 : COPY ./src /app ---> Using cache ---> 177b34cc5674 Step 5/9 : CMD /usr/bin/node /app/app.js ---> Using cache ---> 3c1f8e2407dc Step 6/9 : EXPOSE 7006/tcp ---> Running in 925b1e84e222 ---> eaa8e957002d Removing intermediate container 925b1e84e222 Step 7/9 : EXPOSE 7007/tcp ---> Running in 3bed5ab873f2 ---> 36a58dc9fa46 Removing intermediate container 3bed5ab873f2 Step 8/9 : EXPOSE 7008/tcp ---> Running in d059f2383111 ---> 3c8f23df8971 Removing intermediate container d059f2383111 Step 9/9 : EXPOSE 7009/tcp ---> Running in 095a0e5748c1 ---> 5c04fe5beb8c Removing intermediate container 095a0e5748c1 Successfully built 5c04fe5beb8c [root@xbldockerbuild myapp]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine-node-multiple-ports v1 5c04fe5beb8c 41 seconds ago 32.6 MB
創(chuàng)建容器測(cè)試
[root@xbldockerbuild myapp]# docker run -d -it --name httpserver alpine-node-multiple-ports:v1 d511b5157cbdc40da55623cbf6a3c20a0317eac3e52c3239236ae1c514536044 [root@xbldockerbuild myapp]# docker ps -a |grep httpserver d511b5157cbd alpine-node-multiple-ports:v1 "/usr/bin/node /ap..." 27 seconds ago Up 26 seconds 7006-7009/tcp httpserver [root@xbldockerbuild myapp]# docker inspect httpserver | grep IPAddress "SecondaryIPAddresses": null, "IPAddress": "172.17.0.6", "IPAddress": "172.17.0.6", [root@xbldockerbuild myapp]# curl http://172.17.0.6:7006/ Listening on port 7006 [root@xbldockerbuild myapp]# curl http://172.17.0.6:7007/ Listening on port 7007 [root@xbldockerbuild myapp]# curl http://172.17.0.6:7008/ Listening on port 7008 [root@xbldockerbuild myapp]# curl http://172.17.0.6:7009/ Listening on port 7009
“如何制作多端口httpserver的容器鏡像”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
分享文章:如何制作多端口httpserver的容器鏡像
網(wǎng)站地址:http://www.rwnh.cn/article4/psggoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷(xiāo)推廣、網(wǎng)站策劃、ChatGPT、定制開(kāi)發(fā)、網(wǎng)站導(dǎo)航、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)