In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to make a mirror image of Dockerfile files in docker", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn how to make a mirror image of Dockerfile files in docker.
1. Create an empty directory
$cd / home/xm6f/dev $mkdir myapp$ cd myapp/
2.vim Dockerfile, the content is as follows:
# # A basic python runtime environment FROM python## sets the working directory WORKDIR / app## to copy the contents of the current system folder to the container's app directory ADD. / app## installs the necessary dependency package RUN pip install-r softwares.txt## open port for access to EXPOSE 80EXPOSE 3088EXPOSE 8080EXPOSE 8066 outside the container # defines the environment variable ENV NAME HELLO## runs the command CMD ["python", "app.py"]
3. Installation dependency
Vim softwares.txt, the content is as follows:
FlaskRedis
4.vim app.py, the content is as follows:
From flask import Flaskfrom redis import Redis, RedisErrorimport osimport socket# Connect to Redisredis = Redis (host= "redis", db=0, socket_connect_timeout=2, socket_timeout=2) app = Flask (_ _ name__) @ app.route ("/") def hello (): try: visits = redis.incr ("counter") except RedisError: visits = "cannot connect to Redis Counter disabled "html =" Hello {name}! "\" Hostname: {hostname} "\" Visits: {visits} "return html.format (name=os.getenv (" NAME "," world "), hostname=socket.gethostname (), visits=visits) if _ _ name__ =" _ _ main__ ": app.run (host='0.0.0.0', port=80)
5. Compile
$docker build-t myfirstapp.
6. Check that a new image has been generated
$docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmyfirstapp latest 01ea1129a831 2 hours ago 699MB
7. Start image
$docker run-p 4000 purl 80 myfirstapp
You can also run it in the background:
$docker run-d-p 4000 purl 80 myfirstapp
8. Access servic
# curl http://localhost:4000Hello world!Hostname: a6655d0d7e74Visits: cannot connect to Redis, counter disabled
Or browser access service: http://192.168.1.160:4000
9. View the currently running image
$docker psCONTAINER ID MAGE COMMAND CREATED STATUS PORTS NAMES2db45cab2bb4 myfirstapp "python app.py" 2 minutes ago Up 2 minutes 0.0.0.0 minutes ago Up 4000-> 80/tcp elastic_wilson
10. Stop mirroring
The above $docker stop 2db45cab2bb4 is all the contents of the article "how to make an Image of Dockerfile Files in docker". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.