In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use docker to create a static website". In daily operation, I believe many people have doubts about how to use docker to create a static website. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to use docker to create a static website". Next, please follow the editor to study!
First, create a docker file
The docker files of different servers are different. The following docker files for nginx, apache and tomcat servers are created respectively, which are mainly different from the from tag and the project file directory.
Directory structure plate:
1the docker file of Nginx
From nginxcopy. / www / usr/share/nginx/html/workdir / usr/share/nginx/html/run chown-r daemon:daemon * & & chmod-r 755 * expose 80
2the docker file of Apache
From httpdcopy. / www/ / usr/local/apache2/htdocs/workdir / usr/local/apache2/htdocs/run chown-r daemon:daemon * & & chmod-r 755 * expose 80
3The docker file of Tomcat
From tomcatcopy. / www/ / usr/local/tomcat/webapps/root/webappworkdir / usr/local/tomcat/webapps/root/webapp # change to the project directory run chown-r daemon:daemon * & & chmod-r 755 * # to set permissions
A project named webapp is created here, and / webapp is added after the url address when accessing the project. Also note here that the default port of tomcat is 8080.
Three files are applied to deploy your website in different environments. Set permissions according to the situation, or not.
Second, build the project
Docker build-t imagename. (note that the imagename had better be "hub account name / project name" to facilitate push to the public library.)
The build process is shown below
Third, push to the public warehouse
Docker login login needs to be performed first
Docker push ejiyuan/webapp
Fourth, pull the project on the server
Docker login login needs to be performed first
Docker pull ejiyuan/webapp
Execute docker images to check whether the image exists
Fifth, execute the project
Docker run-d-p 8081 80 ejiyuan/webapp
Sixth, verification
Directly access the host ip address plus the port number 8081 given at startup or use curl
Curl http://192.168.99.100:8081
Seven, problems
For example, if the default page of your project is not index.html, 401 or the following page will appear:
The main reason is that there is no default page specified, use the following command to log in to the image
Docker exec-it containerid / bin/bash
Containerid can be obtained using docker ps. Modify / etc/nginx/conf.d/default.cnf. If there is no vim or vi in the container, install it through the following two commands
Apt updateapt install vim
Or use the sed command
Sed-I '10c index default.html;' / etc/nginx/conf.d/default.conf
Need to reload after modification
Nginx-t # check if the configuration file is incorrect sevice nginx reload # newly load the configuration file
If there is no service, restart the container using docker restart containerid after exiting the container using exit
Eight, contrast
Execute docker images to see the result nginx is the smallest, apache is the second, and tomcat is the largest.
At this point, the study on "how to use docker to create a static website" 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.