Using Docker to create static website applications (multiple ways)

Using Docker to create static website applications (multiple ways)

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

First, create a docker file,

The docker files for different servers are different. The following are the docker files for nginx, apache, and tomcat servers. In fact, the main difference is the FROM tag in the project file directory.

Directory structure:

1. Docker file for nginx

FROM nginx
COPY ./www /usr/share/nginx/html/
WORKDIR /usr/share/nginx/html/RUN chown -R daemon:daemon * && chmod -R 755 *
EXPOSE 80

2. Apache's docker file

FROM httpd
COPY ./www/ /usr/local/apache2/htdocs/
WORKDIR /usr/local/apache2/htdocs/RUN chown -R daemon:daemon * && chmod -R 755 *
EXPOSE 80

3. Docker file of tomcat

FROM tomcat
COPY ./www/ /usr/local/tomcat/webapps/ROOT/webapp
WORKDIR /usr/local/tomcat/webapps/ROOT/webapp #Switch to the project directory RUN chown -R daemon:daemon * && chmod -R 755 * #Set permissions

Here we create a project named webapp. When accessing it, add /webapp after the URL address. Also note that the default port of Tomcat is 8080.

The three files are used to deploy your website in different environments. You can set permissions according to the situation or not.

Second, build the project

 docker build -t imageName . (Note the dot at the end. It is best if imageName is the "hub account name/project name" to facilitate pushing to the public library)

The following shows the build process

3. Push to public warehouse

You need to execute docker login first

docker push ejiyuan/webapp

Fourth, pull the project on the server

You need to execute docker login first

docker pull ejiyuan/webapp

Execute docker images to check whether the image exists

5. Execution of the Project

docker run -d -p 8081:80 ejiyuan/webapp

VI. 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

7. Questions

Here we take nginx as an example. If your project's default page is not index.html, 401 or the following page will appear:

The main reason is that the default page is not specified. Use the following command to log in to the image

docker exec -it containerId /bin/bash

The 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 with the following two commands

apt update
apt install vim

Or use sed command

sed -i '10c index default.html;' /etc/nginx/conf.d/default.conf

Modifications require reloading

nginx -t # Check if the configuration file is correct service nginx reload # Newly load the configuration file

If the service does not exist, exit the container using exit and restart the container using docker restart containerId

8. Contrast

Run docker images and see the results yourself. Nginx is the smallest, Apache is the second, and tomcat is the largest.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementation of static website layout in docker container

<<:  mysql5.7.17.msi installation graphic tutorial

>>:  Example of automatic import method of vue3.0 common components

Recommend

Tutorial on how to connect and use MySQL 8.0 in IDEA's Maven project

First, let's take a look at my basic developm...

Detailed explanation of CocosCreator optimization DrawCall

Table of contents Preface What is DrawCall How do...

js to achieve the complete steps of Chinese to Pinyin conversion

I used js to create a package for converting Chin...

Practice of deploying web applications written in Python with Docker

Table of contents 1. Install Docker 2. Write code...

PyTorch development environment installation tutorial under Windows

Anaconda Installation Anaconda is a software pack...

Font Treasure House 50 exquisite free English font resources Part 2

Designers have their own font library, which allo...

Six methods for nginx optimization

1. Optimize Nginx concurrency [root@proxy ~]# ab ...

An article to teach you HTML

If you are not committed to becoming an artist, t...

Basic knowledge of website design: newbies please read this

Now many people are joining the ranks of website ...

Mobile development tutorial: Summary of pixel display issues

Preface I believe that in the process of mobile t...

How to install MySQL 5.7.29 with one click using shell script

This article refers to the work of 51CTO blog aut...

Summary of the use of CSS scope (style splitting)

1. Use of CSS scope (style division) In Vue, make...

Detailed explanation of the configuration method of Vue request interceptor

Follow the steps below 1. request.js content: htt...

How to add custom system services to CentOS7 systemd

systemd: The service systemctl script of CentOS 7...