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

Windows Server 2008 R2 Multi-User Remote Desktop Connection Licensing

At work, we often need remote servers and often e...

MySQL 8.0.11 Installation Tutorial under Windows

This article records the installation tutorial of...

Install mysql5.7.13 using RPM in CentOS 7

0. Environment Operating system for this article:...

HTML table only displays the outer border of the table

I would like to ask a question. In Dreamweaver, I...

How to use Linux tr command

01. Command Overview The tr command can replace, ...

Common browser compatibility issues (summary)

Browser compatibility is nothing more than style ...

MySql index improves query speed common methods code examples

Use indexes to speed up queries 1. Introduction I...

How to write object and param to play flash in firefox

Copy code The code is as follows: <object clas...

Example of exporting and importing Docker containers

Table of contents Exporting Docker containers Imp...

Pure CSS3 code to implement a running clock

Operation effectCode Implementation html <div ...

Solution to css3 transform transition jitter problem

transform: scale(); Scaling will cause jitter in ...

How to authorize remote connections in MySQL in Linux

Note: Other machines (IP) cannot connect to the M...

How to use async and await in JS

Table of contents 1. async 2. await: 3. Comprehen...