How to run the front-end code on the server, first install Nginx, here I use Docker to install Nginx
Article directory
- 1. Install the nginx docker image
-
-
- 1. Obtain the official image of nginx
- 2. View the mirror library
- 3. The host creates the directory to be mounted
- 4. Start a container that does not mount
- 5. Mount the configuration file to the host
- 6. Stop/delete the container
- 7. View the host file tree
- 8. Restart a container with a mounted directory
-
1. Install the nginx docker image
1. Obtain the official image of nginx
docker pull nginx
2. View the mirror library
docker images
ps: We can see that our nginx mirror download is complete
If we mount the directory when we start it for the first time, because our host is an empty file, the configuration file in the Nginx container will be overwritten directly, causing the startup to fail.
3. The host creates the directory to be mounted
mkdir -p /home/nginx/conf
mkdir -p /home/nginx/logs
mkdir -p /home/nginx/html
-p
The role of the parameter is to allow the creation of multi-level directories
4. Start a container that does not mount
docker run -d --name nginx-test -p 8860:80 nginx
Order | describe |
---|---|
–name nginx | The name of the container to start |
-d | Background process |
-v | map directory |
-p | Native port mapping maps port 8860 of the container to port 80 of the machine |
The last nginx in the statement is the name of the image used |
check it out
Start successfully
5. Mount the configuration file to the host
Copy the nginx.conf file and conf.d folder in the container to the host
Check the name of your Nginx: here is nginx-test
# 将容器nginx.conf文件复制到宿主机
docker cp nginx-test:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf
# 将容器conf.d文件夹下内容复制到宿主机
docker cp nginx-test:/etc/nginx/conf.d /home/nginx/conf/conf.d
# 将容器中的html文件夹复制到宿主机
docker cp nginx-test:/usr/share/nginx/html /home/nginx/
到了,这一步都只是为了获取 Nginx的配置文件
Now that the acquisition is successful, the useless ones can be deleted
6. Stop/delete the container
docker ps -a #View all containers
docker ps View currently running containers
docker stop nginx-test stop nginx container | Container ID is also available, only the first 3 digits are required
docker images view container list
7. View the host file tree
7.1 Install the tree tree
yum install tree
7.2 View tree tree
tree
8. Restart a container with a mounted directory
docker run \
-p 8860:80 \
--name learn-nginx \
-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/nginx/logs:/var/log/nginx \
-v /home/nginx/html:/usr/share/nginx/html \
-d nginx:latest
Check whether the startup is successful, then we will change the html content
and then check it to know