Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Create static website applications using docker (in a variety of ways)

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

There are many servers that can host static websites. This article uses nginx, apache and tomcat servers to demonstrate docker static website application settings.

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.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report