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 introduces the "tutorial on the use of dockerfile". In the daily operation, I believe that many people have doubts about the use of dockerfile. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "tutorial on the use of dockerfile"! Next, please follow the editor to study!
What is dockerfile? To put it simply, it is a script file in text format, which contains instructions (Instruction), each of which is responsible for describing how the current layer of the image (Layer) is built.
Let's learn how to write dockerfile through a concrete example.
Create a new dbuild folder, create a custom Nginx home page, the logic is very simple, display a custom image file train.jpg.
I want to make some changes based on the standard Nginx image to make Nginx support SSL. SSL (Secure Sockets Layer secure Sockets layer) and its successor Transport layer Security (Transport Layer Security,TLS) are security protocols that provide security and data integrity for network communications. TLS and SSL encrypt the network connection at the transport layer.
To do this, I first need to create a configuration file for SSL.
Cat ssl.confserver {listen 443 ssl;server_name localhost;ssl_certificate / etc/nginx/ssl/nginx.crt;ssl_certificate_key / etc/nginx/ssl/nginx.key;location / {root / usr/share/nginx/html;index index.html index.htm;}} _ _ EOF
Create the nginx.key and nginx.crt files using the following command:
Openssl req-x509-nodes-newkey rsa:4096-keyout nginx.key-out nginx.crt-days 365-subj "/ CN=$ (hostname)"
With everything in place, it's time to create a dockerfile:
FROM nginx:stable# copy the custom website into the imageCOPY train.jpg / usr/share/nginx/html/COPY index.html / usr/share/nginx/html/# copy the SSL configuration file into the imageCOPY ssl.conf / etc/nginx/conf.d/ssl.conf# download the SSL key and certificate into the imageCOPY nginx.key / etc/nginx/ssl/nginx.keyCOPY nginx.crt / etc/nginx/ssl/nginx.crt# expose the https portEXPOSE 443
The first line of all dockerfile instructions must be FROM XXXX.
The role of FROM is to specify the base image. The dockerfile is customized based on the image specified later in the FROM.
There are many high-quality official images on Docker Store, which are mainly divided into the following three categories:
Out-of-the-box mirrors of service classes, such as network server nginx, and database servers such as redis, mongo, mysql, etc.
It is convenient to develop, build and run images of applications in various languages, such as node, openjdk, python and so on.
More basic operating system images than the first two categories, such as ubuntu, debian, centos, etc.
Of course, if you do not want to start image construction based on these official images, but want to start from scratch, this is also fine. Docker has a special image called scratch. It's a virtual concept.
Represents a blank mirror.
Using FROM scratch directly makes the image smaller.
The next series of copy instructions are easy to understand.
After the dockerfile development is complete, execute the command:
Docker build-t jerry-nginx:1.0.
It means to start building the image based on the current directory and pay attention to the one at the end. Essential, represents the "current catalog".
Through the log output of docker build execution, you can observe that each line of instructions in it is executed line by line:
The last line of the log indicates that the scene labeled jerry-nginx:1.0 has been successfully built.
Run a container based on the image you just made with the following command:
Docker run-d-p 443-p 1082-80 jerry-nginx:1.0
There is no problem with access based on http protocol:
Http://localhost:1082
Https-based access also works:
Https://localhost:443
At this point, the study on the "tutorial on the use of dockerfile" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.