How to make Image of Dockerfile File in docker
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!