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 > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
It is believed that many inexperienced people don't know what to do about how to install Nginx through Docker in CentOS7.3 server. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1. Pull nginx image docker pull nginx 2. Create host directory nginx-> for mounting the configuration files found in the container below.
Warm Tip:-p: make sure the directory name exists. If it does not exist, recreate a html: static resource directory in the mapping container logs: log file directory conf: configuration file directory conf.d: configuration file subdirectory
Mkdir-p / IT_zhengqing/soft/nginx/html / IT_zhengqing/soft/nginx/logs / IT_zhengqing/soft/nginx/conf/ IT_zhengqing/soft/nginx/conf/ conf.d3. Find the configuration files, log files and other locations in the nginx image container
-> purpose: when running startup nginx, map the configuration file in the host to the configuration file in the container (mount the configuration file in the nginx container to the host)-> that is, after nginx starts, the configuration in the host is used.
(1) start the nginx container in interactive mode and execute the / bin/bash command inside the container-> enter docker run-it-- name nginx-p 81:80 nginx:latest / bin/bash in the nginx container (2) find the location of the configuration file needed in the container
① nginx.conf profile path: / etc/nginx/nginx.conf
Cd / etc/nginx/ls-l
② default.conf profile path: / etc/nginx/conf.d/default.conf
Conf.d: a subdirectory. After the container walks through the nginx.conf configuration file, it will go to the configuration file under the conf.d subdirectory.
Cd / etc/nginx/conf.d/
③ stores static resource folder html path: / usr/share/nginx/html
Cd / usr/share/nginx/
④ log file path: / var/log/nginx
Cd / var/log/nginx (3) finally press the Ctrl+P+Q shortcut key or enter the exit command to exit the container terminal ~ exit 4. Copy the default configuration file of nginx in the container to the host, container name or container ID: execute the docker ps command to view docker cp fb5de6e5638d:/etc/nginx/nginx.conf / IT_zhengqing/soft/nginx/confdocker cp fb5de6e5638d:/etc/nginx/conf.d/default.conf / IT_zhengqing/soft/nginx/conf/conf.d
Warm Tip: copy files from the container to the host: docker cp container name or container ID: the path where the file to be copied in the container is copied to the corresponding path in the host, copy the file from the host to the container: the file path to be copied in the host docker cp the container name or container ID: the corresponding path to be copied to the container
5. Deploy nginx
Warm tip: if the nginx container starts in interactive mode by looking for the configuration file in the container above, if the port conflicts with the port to be used below, you need to stop the corresponding process and the container to run! Check which process the port is occupied by: netstat-lnp | grep port number kills the process [ex: force to kill the process numbered 10001]: kill-9 10001 stops to start the container: docker stop nginx delete container: docker rm-f nginx and then execute docker ps to check the running container. If you successfully delete the container whose port will conflict, then deploy, follow the process below!
Execute the following command to deploy-> start running nginx container docker run-d-p 81:80-- name nginx-v / IT_zhengqing/soft/nginx/html:/usr/share/nginx/html-v / IT_zhengqing/soft/nginx/conf/nginx.conf:/etc/nginx/nginx.conf-v / IT_zhengqing/soft/nginx/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf-v / IT_zhengqing/soft/nginx/logs:/var/log/nginx nginx
-d: start the container in background mode-> run the container in background mode-p 81:80: map port 80 of the container to port 81 of the host. Note: some servers need to release the port manually-- name nginx: name the container nginx-v / IT_zhengqing/soft/nginx/html:/usr/share/nginx/html: mount the html directory created in the host to the container. / usr/share/nginx/html directory be sure to find the exact path where the configuration file is located in the container Otherwise, the operation here will report an error!
Test access (1) create index.html static resource cd / IT_zhengqing/soft/nginx/htmltouch index.html # create file echo 'nginx container running under the host / IT_zhengqing/soft/nginx/html directory. Hello World
If I were you.
'> index.html # echo: create if you don't have this file. If there is this file, then the new content will replace the original content.
You can also use the vi editor to create a file here with the following command:
Vi index.html # then press I to insert, then enter the content, press Esc to exit editing mode, switch to English input method, press shift +: then type wq to exit and save and finally view the contents of the file through the cat index.html command
Here the editor talks about the difference between using the vi command and the echo command to create file writes: if read-only is not set when deploying the nginx runtime, (read-only is to mount the directory followed by: ro such as:-v / data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro)
Echo command-> modify content, host and container configuration files will be changed; vi command-> modify content, host and container configuration will not affect each other. (2) browser input http://ip: port / access test
After reading the above, have you mastered how to install Nginx through Docker in the CentOS7.3 server? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.