In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to make a container image of multi-port httpserver". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Create / root/myapp directory
[root@xbldockerbuild myapp] # tree / root/myapp/root/myapp ├── Dockerfile └── src └── app.js1 directory, 2 files
The contents of app.js and Dockerfile are as follows
[root@xbldockerbuild myapp] # cat src/app.js var http=require ('http'); var ports = [7006, 7007, 7008, 7009]; var servers = []; var Content-Type':'text/plain' 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.8RUN apk updateRUN apk add-no-cache nodejsCOPY. / src / appCMD ["/ usr/bin/node", "/ app/app.js"] EXPOSE 7006/tcpEXPOSE 7007/tcpEXPOSE 7008/tcpEXPOSE 7009/tcp
Making container image by docker build
[root@xbldockerbuild myapp] # dockerbuild-t alpine-node-multiple-ports:v1 .Sending build context to Docker daemon 3.584 kBStep 1 pick 9: FROM alpine:3.8-- > dac705114996Step 2 dockerbuild 9: RUN apk update-- > Using cache-- > a822afa9e3edStep 3 hand 9: RUN apk add-- no-cache nodejs-- > Using cache-- > 325de7d2e3a6Step 4 hand 9: COPY. / src / app-- > Using cache-- > 177b34cc5674Step 5max 9: CMD / usr/bin/node / app/app.js-> Using cache-> 3c1f8e2407dcStep 6 EXPOSE 7008/tcp 9: EXPOSE 7006/tcp-- > Running in 925b1e84e222-- > eaa8e957002dRemoving intermediate container 925b1e84e222Step 7 EXPOSE 7008/tcp 9: EXPOSE 7007/tcp-> Running in 3bed5ab873f2-- > 36a58dc9fa46Removing intermediate container 3bed5ab873f2Step 8 EXPOSE 7008/tcp 9: EXPOSE 7008/tcp-- > Running in d059f2383111-- > 3c8f23df8971Removing intermediate container d059f2383111Step 9 EXPOSE 7009/tcp-> Running in 095a0e5748c1-> 5c04fe5beb8cRemoving intermediate container 095a0e5748c1Successfully built 5c04fe5beb8c [root@xbldockerbuild myapp] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEalpine-node-multiple-ports v1 5c04fe5beb8c 41 seconds ago 32.6 MB
Create a container test
[root@xbldockerbuild myapp] # docker run-d-it-- name httpserver alpine-node-multiple-ports:v1d511b5157cbdc40da55623cbf6a3c20a0317eac3e52c3239236ae1c514536044 [root@xbldockerbuild myapp] # docker ps-a | grep httpserverd511b5157cbd 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
This is the end of "how to make a container image of a multi-port httpserver". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.